Report this

What is the reason for this report?

Any way to leverage user data init scripts on top of a custom AMI?

Posted on July 18, 2021

Hi,

Wondering if it is possible to leverage the digital ocean droplet user_data field to run custom boot scripts on top of a pre-existing baseline snapshot.

The thinking being, that for setting up remote developer environments, it would be a significant time save to create a snapshot with a bunch of pre-configured libraries, and to follow up with an initialization script when a new developer environment droplet is created.

Unfortunately, at least from my testing, it seems like user_data scripts cannot be run against a snapshot, only a fresh install.

Is this the case, or am I missing something (hoping for the latter 🤞)



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!

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.

Hey!

Yes, you can use the user_data field to run custom boot scripts on a DigitalOcean Droplet created from a pre-existing snapshot.

This is possible as long as CloudInit is available on the Droplet. CloudInit, available on DigitalOcean’s latest Ubuntu images, can consume the user data to perform tasks as the root user during the Droplet’s first boot.

You can define user data for images that do not support CloudInit, but it will not be consumed automatically on first boot. To provide user data, you can use the DigitalOcean Control Panel, API, or the CLI client doctl during Droplet creation.

However, remember that you cannot modify user data after a Droplet is created. For debugging, you can check the /var/log/cloud-init-output.log file to see how CloudInit is using the provided user data:

https://docs.digitalocean.com/products/droplets/how-to/provide-user-data/

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.