TDM can connect to databases on cloud and do the masking as long as you have network connection and supported database. However, network latency will delay the masking performance. It is always recommended to install FDM closer to your database, in this case in the cloud. Meaning, it would be better if you can also install FDM on the cloud to run the masking.