6
votes

I am very new to AWS. I have a Windows Server EC2 instance. I installed AWS CLI on my laptop. Then I opened a CMD window, typed in "aws configure", put in the access key credentials, and was able to connect to the EC2.

From here, how do I get the http://169.254.169.254/latest/meta-data working? How do I retrieve some meta data?

3

3 Answers

7
votes

On your Laptop

On your local machine you only can use the cli to retrieve metadata about your instance. Simply use this aws cli command:

aws ec2 describe-instance-attribute --instance-id <your-ec_instance_id e.g. i-ab12345> --attribute instanceType --region <your_region e.g. eu-west-1>

Documentation: http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instance-attribute.html

On your EC2-Instance only: On your instance you can use the cli (like above) and the following:

PowerShell >3.0:

Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/instance-type

Documentation: http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html

Or you can install "curl for windows" and run:

curl http://169.254.169.254/latest/meta-data/instance-type
6
votes

When running on an EC2 instance, you can query the metadata service, like so:

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

You can also use:

curl http://instance-data/latest/meta-data/public-ipv4

From outside the EC2 instance, you can use the awscli, like so:

aws ec2 describe-instances
    --instance-ids i-01234567890123456
    --query "Reservations[0].Instances[0].PublicIpAddress"
    --output text
1
votes

You cannot use http://169.254.169.254/latest/meta-data from AWS cli on your laptop

Use the ec2 describe-instances command instead for getting instance details

More details here