I am attempting to load user data into an Ubuntu 12.04 LTS AMI (ami-a29943cb, but I've tried a few others to no avail) via boto's ec2.run_instances(..., user_data=USER_DATA). Similarly, I have had no success with manually supplying the user data while launching the instances via the AWS console. There are no results or messages in /var/logs/syslog for any of the methods I've tried.
USER_DATA looks something like the following, read in as a string from a file:
#!/usr/bin/env python
import boto
AWS_BOOTSTRAP_BUCKET = ''
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
# Pull processing script from S3.
print 'Bootstrapping started.....'
print 'Connecting to S3...'
s3 = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = s3.get_bucket(AWS_BOOTSTRAP_BUCKET)
print 'Downloading bootstrap file...'
key = bucket.get_key('xxx')
key.get_contents_to_filename('xxx')
print 'Importing Bootstrap file...'
import xxx
xxx.process()
# Shut down the EC2 instance running this process.
print 'Shutting down this instance...'
import socket
desired_hostname = socket.gethostname()
ec2 = boto.connect_ec2(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
reservations = ec2.get_all_instances()
for reservation in reservations:
for instance in reservation.instances:
if desired_hostname in instance.private_dns_name:
instance.terminate()
I have furthermore tried uploading the file to a public S3 bucket and loading it in this manner, once again to no avail:
#include
https://s3.amazonaws.com/bucket/file.py
Does anyone have any advice in this regard? Am I completely misunderstanding the purpose of user-data/cloud-init or is the technology merely broken in the AMI I am trying to utilize?
Tip: If you add set -x at the top of a bash script, then it will output every command executed. If you add set -e to the script, then the user-data script will exit on the first command which does not succeed. These help you quickly identify where problems might have started.
source – Callaway