Is there a means to create a droplet with a cost limit?
Suppose I am building a service on top of Digital Ocean droplets, and I want to purchase some free trial time for users. Lets say I want to create droplets on their behalf to run a service in a sandboxed manner.
Is there a way to set a limit on a droplet’s cost use. EG, I want to create a droplet but not have it spend more than 10 cents. If it reaches 10 cents, it auto-destroys.
I want to have a guarantee that a malicious user or mistake will not accidentally burn a bunch of cash.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
@williamsharkey
This isn’t something that is possible by default – you’d have to bake this in to your application.
When a Droplet is created using the API, you’ll receive a JSON object as a response and within it, you can pull
created_at
, which is described as:A time value given in ISO8601 combined date and time format that represents when the Droplet was created
To get the total time that a Droplet has been active, you’d simply get the different between the current time and the one provided by
created_at
. You’d then compare that against however long you allow them to use the service for free and if it meets or exceeds, issue a destroy command.https://developers.digitalocean.com/documentation/v2/#create-a-new-droplet
You can use the API to monitor your droplets and destroy them if necessary.