Thomas Huerta
Thomas Huerta

Reputation: 65

Determine current AWS region .Net?

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.

Upvotes: 5

Views: 5333

Answers (2)

James Thorpe
James Thorpe

Reputation: 32212

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".

Upvotes: 6

jarmod
jarmod

Reputation: 78842

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.

Upvotes: 0

Related Questions