Easiest way to get EC2 instance attributes within the instance itself

There's a much easier method than making a web API call, the .NET SDK.

See the SDK documentation for EC2InstanceMetadata here

For example, if you need InstanceId you can use:

Amazon.Util.EC2InstanceMetadata.InstanceId.ToString();

All the other properties are available in a similar manner.

Note that the SDK used to have Amazon.EC2.Utils - this was deprecated in 2015 and moved to Amazon.Util namespace


There's a webservice that returns machine information. Access

http://169.254.169.254/latest/meta-data/instance-id

To retrieve the instance id

The Instance Metadata Documentation can be handy.


You can also use AWS's Dot Net SDK for example Amazon.EC2.Util.EC2Metadata.InstanceId.ToString();