I can't speak to the cloud aspect as I avoid the use of the cloud unless forced to use it for some reason. What you are--effectively--asking is: Can you connect to a remote database? The answer is a pretty obvious yes. You'd do it like you would to any remote database. You need an address for it. Doing so isn't intrinsically different from connecting to a database on the same machine the program is running one. Locally, the address will be "localhost".
What you might do is start by using a database installed on the Pi that is collecting the sensor data. Once that is working, create a program that copies that data to a "remote" database on your LAN. Once that is working, connect to a remote host somewhere else, like a cloud server.
Depending on what database engine you are using, you might be able to set up your cloud-based database a replicated slave of your local one. While I don't do it with the cloud, I do that with a pair of SBCs using MySQL. Data is written to the database on one system and the other automatically grabs it and populates a duplicate database with no programming (beyond replication set up) being done on my part.