简体   繁体   English

未执行AWS EC2用户数据(使用python sdk boto)

[英]AWS EC2 user data NOT executed (using python sdk boto)

I search a lot, seems nobody had any problem with this. 我搜索了很多东西,似乎没有人对此有任何问题。

Probably there's a problem with my code, but I really can't find it. 我的代码可能存在问题,但我确实找不到它。

this is my user-data-script.sh 这是我的user-data-script.sh

#!/bin/sh

su root
cd /var
mkdir www

this is the python script I'm using for launching the instance 这是我用于启动实例的python脚本

#!/usr/bin/python

import boto.ec2

def get_script(filename='user-data-script.sh'):
    return open(filename).read()

def launch():
    connection = boto.ec2.connect_to_region('us-east-1')
    return connection.run_instances(
        image_id = 'ami-6ba27502',
        instance_type = 't1.micro',
        key_name = 'forSSH',
        security_groups = ['default'],
        user_data=get_script(),
    )

if __name__ == '__main__':
    launch()

and after the instance is ready. 并准备好实例后。 I ssh into it, I can't find /var/www :( 我ssh进去了,我找不到/ var / www :(

this is the last few line in /var/log/cloud-init.log 这是/var/log/cloud-init.log中的最后几行

[CLOUDINIT] cloud-init-cfg[INFO]: cloud-init-cfg ['all', 'final']
[CLOUDINIT] __init__.py[DEBUG]: handling rightscale_userdata with freq=None and args=[]
[CLOUDINIT] __init__.py[DEBUG]: handling scripts-per-once with freq=None and args=[]
[CLOUDINIT] __init__.py[DEBUG]: handling scripts-per-boot with freq=None and args=[]
[CLOUDINIT] __init__.py[DEBUG]: handling scripts-per-instance with freq=None and args=[]
[CLOUDINIT] __init__.py[DEBUG]: handling scripts-user with freq=None and args=[]

ps: I'm NOT trying to setup HTTP server, ps:我不是要设置HTTP服务器,

the su root; cd /var; mkdir www su root; cd /var; mkdir www su root; cd /var; mkdir www su root; cd /var; mkdir www is just something to try. su root; cd /var; mkdir www只是一个尝试。

user_data脚本以root身份运行,因此您不需要“ su root”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM