0

Is it possible to add a custom CloudInit part handler directly to an AMI so that it is available to all new instances without having to add it to the user data every time?

I have a couple of custom MIME types we use to define configuration data for our EC2 cloud instances and the #part-handler python scripts necessary to process them. I'd like to streamline the instance creation process by eliminating the need to include these part handlers in the user data every time I create a new instance. Is there some hook in the CloudInit scripts where I could add my part handlers directly to the AMI so that the only thing I'd need to pass in via user data is the config files themselves?

mgorven
  • 30,615
  • 7
  • 79
  • 122
Mike Deck
  • 183
  • 1
  • 1
  • 7

2 Answers2

3

There doesn't seem to be a plugin mechanism, but would you could do is host the configuration on an HTTP server and just include it when launching the instance instead of repeating it:

begins with "#include" or "Content-Type: text/x-include-url"
This content is a "include" file. The file contains a list of urls, one per line. Each of the URLs will be read, and their content will be passed through this same set of rules. Ie, the content read from the URL can be gzipped, mime-multi-part, or plain text

mgorven
  • 30,615
  • 7
  • 79
  • 122
0

Have just spent a few hours on the matter and found out you can actually save the part-handler under /var/lib/cloud/handlers but there are a few caveats.

I am uncertain if there should be a specific pattern to the filename but in my case I saved it as /var/lib/cloud/handlers/part-handler-000.py and created an AMI out of it.

When launching a new instance based on that AMI it seems that the userdata for that mime has to be supplied inside a multipart mime (Yes, even if that multipart just contains your own part).

I did try to send the following as the first line

Content-Type: text/XXXXX;

or

#XXXXX

but none worked

ByteFlinger
  • 193
  • 1
  • 1
  • 7