Instance Metadata is data about an EC2 instance and includes
information such as instance Id, AMI Id, VPC id, subnet id, etc. Instance metadata
can be accessed from within the Instance itself as it's not protected by any
authentication or cryptographic methods. Anyone having access to the instance
can access this metadata.
Sometimes we don’t have access to the AWS console or just have
access to only the EC2 instance and want to get information like where it is
hosted in AWS Cloud and other AWS-related information about an EC2 instance.
How to access EC2 Instance Metadata?
EC2 Instance metadata can be accessed by running the curl or
GET command inside the instance. We can also use the Invoke-WebRequest command
to query the instance metadata stored in default IP address 169.254.169.254,
this IP address is the same for all the EC2 instances running in AWS Cloud.
In this article, we are going to give you a PowerShell script
that will fetch the EC2 instance metadata from a windows EC2 instance by using
the Invoke-WebRequest PowerShell cmdlet.
Below are the details which we are going to retrieve from instance metadata, one can fetch other details apart from these from the EC2 Instance metadata.
- AWS Account Number
- Instance Id
- AMI Id
- VPC Id
- Subnet Id
- Instance Type
- Availability Zone
- Region
- Security Groups