我试图通过boto的ec2.run_instances(…,user_data = USER_DATA)将用户数据加载到Ubuntu 12.04 LTS AMI(ami-a29943cb,但我已经尝试了其他一些无效)。 同样,我通过AWS控制台启动实例时手动提供用户数据也没有成功。 对于我尝试过的任何方法,在/ var / logs / syslog中都没有结果或消息。
USER_DATA看起来像下面的内容,从文件中以string的forms读入:
#!/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()
我还尝试将file upload到一个公共的S3存储桶,并以这种方式加载它,再次无济于事:
#include https://s3.amazonaws.com/bucket/file.py
有没有人在这方面有任何build议? 我完全误解了user-data / cloud-init的目的,还是仅仅是我正在尝试使用的AMI中的技术?
很难知道发生了什么,没有错误信息,但有几个地方你可以看看:
/var/log/cloud-init.log
通常包含实例引导期间发生的任何错误(例如boto导入失败)。 /var/lib/cloud/instance
将包含下载到实例的原始脚本和用户数据 看这些地方应该有助于提供清晰。
我知道Ubuntu 12.04自带boto 2.2.2:
root@vanilla-562c:/var/lib/cloud/instance# python Python 2.7.3 (default, Apr 20 2012, 22:44:07) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import boto >>> boto.__version__ '2.2.2'
..但我不知道它是否实际上在您的PYTHONPATH在运行时访问。