How can you find out where your EC2 user data script is failing?
-
25-05-2021 - |
質問
I have the following user-data script in my CloudFormation template:
"UserData" : {"Fn::Base64" : {"Fn::Join" : ["", [
"#!/bin/bash\n",
"cd /home/www","\n",
"sudo su www","\n",
"git clone git@github.com:company-name/web-app.git -b master2 app","\n",
"cd app","\n",
"phing clean prepare configure -Dpropsfile ./build/props/build.ec2.properties","\n",
"\n",
"/opt/aws/bin/cfn-signal",
" -e $?",
" '", {"Ref" : "WebServerPort"}, "'",
"\n"
]]}},
This runs a preconfigured private ami we based on the default cloudformation template If I launch an instance on my own I can run through the git/build process w/o error But when cloudformation launches a server, it appears as it has never run
解決
Looks like since I created the AMI from an instance that cloudformation launched, it already ran the init scripts and cached them as 'run' thus any new instances would already have those cached files and never run my script.
sudo rm /var/lib/cloud/sem/user-scripts.*
sudo rm /var/lib/cloud/sem/consume_userdata.*
Then making a new AMI allowed it to work for my own init script
Also dont use su, instead chown afterwards :)
所属していません StackOverflow