| by Arround The Web | No comments

Understanding Instance Metadata and User Data

AWS is the most widely used cloud-based platform offering more than 200 services to millions of customers across the globe. EC2 is the classical service of the AWS infrastructure and it allows the user to create virtual machines of servers on the cloud. Each server contains metadata that can be used to get an understanding of the EC2 instance running on the AWS cloud.

This guide will explain the metadata of the EC2 instance and provides a basic understanding of the topic.

Understanding Instance Metadata and User Data

To understand the metadata of the instance, simply visit the EC2 dashboard from the AWS Management Console:

Configure the Instance
Create an EC2 instance from the service dashboard and configure the “Advanced details” section by expanding it from the launching Instance page:

Configure Metadata Accessible
Locate the “Metadata accessible” section and select the “Enabled” option from the list:

Configure Metadata Version
The “Metadata version” section is placed under the Metadata accessible section to select the “V2 only (token required)” option from the list:

Connect to EC2 Instance
After configuring the EC2 instance, simply connect to it using the key pair file’s path from the local system and the public DNS of the instance with the “ssh” command. The connection process is also available in the guide for configuring the EC2 instance step:

Extract Metadata
After connecting to the instance, use this address inside the address to get the metadata of the instance:

curl http://169.254.169.254/latest/meta-data/

The following screenshot displays that the metadata is not available as the user needs to generate the token to extract the metadata of the instance:

Get Token
After that, simply use the following command to get a token for extracting the metadata of the instance:

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`

Extract Metadata Using Token
Get the metadata of the instance using the following command with the token generated in the previous step:

curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/

Understanding Instance Metadata

The above screenshot displays the list of metadata fields of the EC2 instance and these are mentioned below:

AMI ID
Amazon Machine Image ID is the identity number for the operating system used in the EC2 instance on the cloud.

AMI Launch Index
Launch index explains the number of machine images being used in the AWS account and it starts from the “0” index.

AMI Manifest Path
The Manifest path of the AMI is created when a new AMI is registered which will be displayed under private images.

Block Device Mapping
The block device mapping refers to the components attached to the EC2 instance like EBS storage device, volume, etc.

Events
Events refer to the process that is going on with the EC2 instance like Maintenance.

Hostname
The hostname of the EC2 instance consists of the IPv4 address of the instance and its resource name.

Identity Credentials
The identity credentials of the EC2 instance are used to identify the EC2 instance from the rest of the EC2 infrastructure.

Instance Action
It refers to what is happening inside the EC2 instance or what actions an instance is performing now.

Instance ID
The instance ID is the unique identity number an instance is given at the time of its creation which can be used to identify it from the list.

Instance Life Cycle
The instance life cycle explains the type of instance from the AWS instance types like On-demand, Spot, etc.

Instance Type
The instance type contains the type of the Amazon Machine Image for the EC2 instance.

Local Hostname
It contains the private IPv4 address and the resource name.

Local IPv4
The local IPv4 address is the private address of the EC2 instance to use it privately away from the internet.

Mac
The Mac is the IPv6 address of the EC2 instance.

Metrics
The metrics are the logs or metrics stored in the CloudWatch service about the EC2 instance.

Network
The metadata of the EC2 instance also explains the network to which the EC2 instance is located.

Placement
It explains the AWS region of the EC2 instance like us-east-1 or other.

Profile
The profile in the EC2 instance’s metadata refers to the IAM user which is also called profile in the AWS cloud.

Public Hostname
It is also the hostname that contains the public IPv4 address of the instance and the resource of the instance.

Public IPv4
Public IPv4 is the public address of the instance which can be used to connect to the instance publicly.

Public Keys
Public keys are attached by the user which are downloaded and located on the local system and can be used to connect to the EC2 instance using SSH client.

Reservation ID
The reservation ID of the EC2 instance has a one-to-one relationship with the instance launch request as each instance has the reservation ID.

Security Groups
Security groups are the groups attached to the instance that can be used to control the incoming or outgoing traffic from different endpoints.

Services
The services in the metadata of the instance refer to the activities of the EC2 instance during its lifecycle.

That is all about understanding the Metadata and the user data of the EC2 instance.

Conclusion

To understand the metadata of the EC2 instance, the user needs to visit the EC2 service dashboard and launch the instance by configuring metadata sections. Launch the instance and then connect to it using the SSH client and path of the key pair file from the system and allow the connection. Generate the token and then use it to get the metadata of the instance and this guide explains each term individually.

Share Button

Source: linuxhint.com

Leave a Reply