Hello, I’m fairly new to Digital Ocean and Managed Databases and I’ve been having some trouble getting things wired up.
I created an App using the App Platform and have a Managed Database and a handful of Functions in it. I am trying to get one of the Functions to write data to the Managed Database and have been unsuccessful so far. Can anyone provide some steps or documentation on this? Specifically, I am confused about what environment variables are available at runtime and how to use them to connect to the databases within my Managed Database.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sorry to hear you’re having trouble. We have some documentation on managing databases, though it sounds like you may be past that.
With regard to variables, bind variables can be used to inject credentials for connecting to a database. For example, if you have a database resource called “my-db” you could add an environment variable to your app (or a sub component) with the value:
Key: DB_URL
Value: ${my-db.DATABASE_URL}
From within your app the environment variable $DB_URL will contain the connection string for your database. Pass that to your DB client of choice and you should be able to read and write.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.