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

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

问题描述

代码:

#!/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/cloud/instance/scripts/part-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.

但是就是这样,脚本似乎没有执行.按照 this answer 我检查了 /var/log/cloud-init.log 文件,但它似乎没有包含与我的脚本相关的任何错误消息(好吧,也许我遗漏了一些东西 - here是带有 cloud-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).

我错过了什么?

推荐答案

这可能不再相关,但还没有.我刚刚将 boto 与 ubuntu 和用户数据一起使用,虽然文档说用户数据必须是 base64 编码的,但只有当我将 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()),然后将其作为 user_data 参数传递给 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天全站免登陆