Question:
if I have a AWS CloudFormation template using UserData block containing script block to be executed, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/bash\n", "apt-get update\n", "apt-get -y upgrade\n", ] ] } } |
After the instance is created,
- I assume that this script block will be saved somewhere to be execute?
- If so, where can I find this script on the EC2 instance?
- Will AWS remove this temporary script after stack is created successfully?
I could not find they mention in the doc.
Thanks
Answer:
The user-data for an instance is available for any process on the instance to retrieve at this location:
1 2 |
http://169.254.169.254/latest/user-data |
The DNS name “instance-data” resolves to that IP address, so if you trust DNS to be up, you can also use the easier to remember:
1 2 |
http://instance-data/latest/user-data |
Here are the Amazon docs:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html