3
votes

I am trying to automate ec2 creation. I start an instance from a custom AMI, and specify a user data script during launch configuration. I have noticed that user data script is not being executed. How can I troubleshoot this and what am I missing? Maybe I can specify the script somewhere in AMI ? Thank you in advance.

My startup script :

#!/bin/sh
sudo su
systemctl start docker
docker run -it --publish 8080:8080 exampleapplication:latest

UPDATE : i removed the sudo su and added an echo command for debugging. I checked the system logs and saw my echoed string. And this is what i got for next lines

[   16.291460] cloud-init[3200]: plsssssss
[   17.378345] bridge: filtering via arp/ip/ip6tables is no longer available by default. Update your scripts to load br_netfilter if you need this.
[   17.394716] Bridge firewalling registered
[   17.412835] nf_conntrack version 0.5.0 (8192 buckets, 32768 max)
[   17.479117] Initializing XFRM netlink socket
[   17.489731] Netfilter messages via NETLINK v0.30.
[   17.502725] ctnetlink v0.93: registering with nfnetlink.
[   17.546680] IPv6: ADDRCONF(NETDEV_UP): docker0: link is not ready
[   18.114688] cloud-init[3200]: the input device is not a TTY
[   18.121279] cloud-init[3200]: May 31 15:11:07 cloud-init[3200]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
[   18.131795] cloud-init[3200]: May 31 15:11:07 cloud-init[3200]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
[   18.142379] cloud-init[3200]: May 31 15:11:07 cloud-init[3200]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
1
Did you check the Use Data log? /var/log/cloud-init-output.log - John Rotenstein
Wait you saw the echo output in the logs? If so, then user data is running. - Rodrigo M
Continue to add echo before each command and confirm how far it's running - Rodrigo M

1 Answers

1
votes

I suspect that the first 'sudo su'. That is launching new non-login root shell. It may be affecting execution of the existing shell, where user data is running. It's not needed. Not sure why you have it there. User data runs as root anyway.

Replace it with an 'echo start'. And relaunch. Check your system log and you should see that Echo in the Management console

UPDATE

Also add this https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-log-user-data/

This is a major lifesaver for trouble shooting user data issues.