Determine current AWS region .Net?

4.8k views Asked by At

Is there a way to determine the current AWS region in .Net?

I've been able to find a way to do this in java https://aws.amazon.com/blogs/developer/determining-an-applications-current-region/ but cannot find the equivalent in .Net.

2

There are 2 answers

2
James Thorpe On BEST ANSWER

If you're using the .NET SDK, it's as simple as

var region = Amazon.Util.EC2InstanceMetadata.Region;

It has two main properties, DisplayName and SystemName. The former gives you strings such as "EU West (London)", while the latter gives "eu-west-2".

0
jarmod On

This information is available on an EC2 instance from the EC2 Metadata Service. Actually, only the Availability Zone is available but you can infer the region from the AZ.

It looks like this is available in the .Net SDK via Amazon.EC2.Util and EC2Metadata.