Download EC2 User Guide for Linux - Documentation

Transcript
Amazon Elastic Compute Cloud User Guide for Linux
Instances
Instance Metadata and User Data
Adding User Data
When you specify user data, note the following:
• User data is treated as opaque data: what you give is what you get back. It is up to the instance to be
able to interpret it.
• User data is limited to 16 KB. This limit applies to the data in raw form, not base64-encoded form.
• User data must be base64-encoded before being submitted to the API. The EC2 command line tools
perform the base64 encoding for you. The data is decoded before being presented to the instance. For
more information about base64 encoding, see http://tools.ietf.org/html/rfc4648.
• User data is executed only at launch. If you stop an instance, modify the user data, and start the
instance, the new user data is not executed automatically.
To specify user data when you launch an instance
You can specify user data when you launch an instance. For more information, see Launching an
Instance (p. 231), cloud-init (p. 112), and Running Commands on Your Linux Instance at Launch (p. 286).
To modify the user data for an Amazon EBS-backed instance
1.
2.
3.
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, click Instances, and select the instance.
Click Actions, select Instance State, and then click Stop.
Warning
When you stop an instance, the data on any instance store volumes is erased. Therefore,
if you have any data on instance store volumes that you want to keep, be sure to back it up
to persistent storage.
4.
5.
6.
In the confirmation dialog box, click Yes, Stop. It can take a few minutes for the instance to stop.
With the instance still selected, click Actions, select Instance Settings, and then click View/Change
User Data. Note that you can't change the user data if the instance is running, but you can view it.
In the View/Change User Data dialog box, update the user data, and then click Save.
Retrieving User Data
To retrieve user data, use the following URI:
http://169.254.169.254/latest/user-data
Requests for user data returns the data as it is (content type application/x-octetstream).
This shows an example of returning comma-separated user data.
$ curl http://169.254.169.254/latest/user-data
1234,john,reboot,true | 4512,richard, | 173,,,
This shows an example of returning line-separated user data.
$ curl http://169.254.169.254/latest/user-data
[general]
instances: 4
293