Cost-Limited Droplet Creation w/ auto-destroy

Posted February 7, 2017 2.9k views

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.

Submit an Answer
2 answers

You can use the API to monitor your droplets and destroy them if necessary.

  • Monitoring and destroying is a strategy that is ‘active’, and default-fail. If the monitor fails to act, I am on the hook.

    I am interested in a passive solution.

    If the limit could be set at creation-time of the droplet that would differentiate this product from other cloud services.

    I can kind of imagine that it might be difficult from an engineering perspective to actually place a guarantee on process killing – as I think it is fundamentally an active process to monitor use, and operating systems and hardware do not truly support this feature at the bare-metal level. If I’m wrong about this I would love to hear about it.


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.