Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudFormation where will UserData be stored?

if I have a AWS CloudFormation template using UserData block containing script block to be executed, for example:

"UserData": {
    "Fn::Base64": {
        "Fn::Join": [
            "",
            [
                "#!/bin/bash\n",
                "apt-get update\n",
                "apt-get -y upgrade\n",
            ]
        ]
    }
}

After the instance is created,

  1. I assume that this script block will be saved somewhere to be execute?
  2. If so, where can I find this script on the EC2 instance?
  3. Will AWS remove this temporary script after stack is created successfully?

I could not find they mention in the doc.

Thanks

like image 447
Nam Nguyen Avatar asked Nov 01 '13 02:11

Nam Nguyen


People also ask

Where is UserData script stored?

When a user data script is processed, it is copied to and run from /var/lib/cloud/instances/ instance-id / . The script is not deleted after it is run. Be sure to delete the user data scripts from /var/lib/cloud/instances/ instance-id / before you create an AMI from the instance.

How do I pass UserData in CloudFormation?

2 Answers. Show activity on this post. Inside your template, use a CloudFormation parameter for the instance userdata: { "Parameters": { "UserData": { "Type": "String" } }, "Resources": { "Instance": { "Type" : "AWS::EC2::Instance", "Properties" : { "UserData" : { "Ref" : "UserData" }, ... } }, ... } }

Where are AWS CloudFormation templates stored?

If you specify a template file stored locally, CloudFormation uploads it to an S3 bucket in your AWS account. CloudFormation creates a bucket for each region in which you upload a template file. The buckets are accessible to anyone with Amazon Simple Storage Service (Amazon S3) permissions in your AWS account.


1 Answers

The user-data for an instance is available for any process on the instance to retrieve at this location:

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:

http://instance-data/latest/user-data

Here are the Amazon docs:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

like image 77
Eric Hammond Avatar answered Nov 10 '22 15:11

Eric Hammond