EC2实例加载我的用户数据的脚本,但不运行它 [英] EC2 instance loads my user-data script but doesn't run it

查看:246
本文介绍了EC2实例加载我的用户数据的脚本,但不运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code:

#!/usr/bin/env python

import boto.ec2

conn_ec2 = boto.ec2.connect_to_region('us-east-1') # access keys are environment vars

my_code = """#!/usr/bin/env python

import sys

sys.stdout = open('file', 'w')
print 'test'
"""
reservation = conn_ec2.run_instances(image_id = 'ami-a73264ce',
                                     key_name = 'backendkey',
                                     instance_type = 't1.micro',
                                     security_groups = ['backend'],
                                     instance_initiated_shutdown_behavior = 'terminate',
                                     user_data = my_code)

该实例开始与正确的设置(这是公众的Ubuntu 12.04,64位图像),我可以SSH到它正常。用户数据的脚本似乎是正确装入:我可以看到它在 /var/lib/cloud/instance/user-data.txt (也在的/ var / lib中/云/实例/脚本/一部分-001 )和EC2控制台上。

The instance is initiated with the proper settings (it's the public Ubuntu 12.04, 64-bit, image) and I can SSH into it normally. The user-data script seems to be loaded correctly: I can see it in /var/lib/cloud/instance/user-data.txt (and also in /var/lib/cloud/instance/scripts/part-001) and on the EC2 console.

但仅此而已,剧本似乎并没有被执行。继这个答案我检查了 /var/log/cloud-init.log 文件,但它似乎并没有包含与我的脚本任何错误信息(好吧,也许我失去了一些东西 - 的这里是一个要点与云init.log的内容)。

But that's it, the script doesn't seem to be executed. Following this answer I checked the /var/log/cloud-init.log file but it doesn't seem to contain any error messages related to my script (well, maybe I'm missing something - here is a gist with the contents of cloud-init.log).

我在想什么?

推荐答案

这可能是不相关了,但还没有。 我只是用博托与Ubuntu和用户数据,虽然documenation说,用户数据必须Base64的EN codeD,它只是工作对我来说,如果我通过了64位放慢参数为正常的字符串。

This is probably not relevant anymore, but yet. I've just used boto with ubuntu and user data, although the documenation says that the user data has to be base64 encoded, it only worked for me if I pass the 64 bit paramter as regular string.

我读取用户数据从文件中的内容(使用fh.read()),然后就通过这作为中的用户数据参数设置为run_instances。

I read the content of user data from file (using fh.read()) and then just pass this as the user_data paramter to run_instances.

这篇关于EC2实例加载我的用户数据的脚本,但不运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆