Search code examples
.netamazon-web-servicesaws-sdk-net

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.


Solution

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