User-data scripts is not running on my custom AMI, but working in standard Amazon linux

后端 未结 11 1385
南方客
南方客 2020-12-08 02:15

I searched a lot of topic about \"user-data script is not working\" in these few days, but until now, I haven\'t gotten any idea about my case yet, please help me to figure

11条回答
  •  盖世英雄少女心
    2020-12-08 02:19

    User Data should execute fine without using #cloud-boothook (which is used to activate the User Data at the earliest possible time during the boot process).

    I started a new Amazon Linux AMI and used your User Data, plus a bit extra:

    #!/bin/bash
    
    echo 'bar' > /tmp/bar
    echo 'test' > /home/ec2-user/user-script-output.txt
    echo 'foo' > /tmp/foo
    

    This successfully created three files.

    User Data scripts are executed as root, so it should have permission to create files in any location.

    I notice that in your supplied code, one example refers to /home/ec2-user/user-script/output.txt (with a subdirectory) and one example refers to /home/ec2-user/user-script-output.txt (no subdirectory). The command would understandably fail if you attempt to create a file in a non-existent directory, but your "Update" example seems to show that it did actually work.

提交回复
热议问题