AWS: Difference between User data and Metadata tags when creating EC2 instance

9.7k Views Asked by At

Amazon EC2 instances can be created with 'User Data' (a long string), or metadata tags (a number of key/value pairs).

What is the difference between these? Why do these two systems exist in parallel?

In particular, I wish to pass certain pieces of custom data (i.e. a connection string and two resource URLs) to an EC2 machine on startup so it can configure itself. Presumably these are best sent as three key/value pairs?

3

There are 3 best solutions below

1
On

According to this documentation page, Metadata provided by Amazon and User Data specified by the user:

Amazon EC2 instances can access instance-specific metadata as well as data supplied when launching the instances.

You can use this data to build more generic AMIs that can be modified by configuration files supplied at launch time. For example, if you run web servers for various small businesses, they can all use the same AMI and retrieve their content from the Amazon S3 bucket you specify at launch. To add a new customer at any time, simply create a bucket for the customer, add their content, and launch your AMI.

0
On

Instance metadata is data use to configure or manage the running instance. for example, host name, events, and security groups.

User Data specified by the user, for example, you added a new bucked, its unique bucked name will be part of user data.

Source: https://docs.amazonaws.cn/en_us/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

0
On

Instance Metadata Service: Get details about EC2 instance from inside an EC2 instance. Such as AMI ID, storage devices, DNS hostname, instance id, instance type, security groups, IPaddresses etc

Userdata - Used for bootstrapping. Install OS patches or software when an EC2 instance is launched.

In your following case, you have to use userdata.

I wish to pass certain pieces of custom data (i.e. a connection string and two resource URLs) to an EC2 machine on startup so it can configure itself