Seeing your Amazon EC2 Regions and Availability Zones - AWS SDK for .NET

Do you want to deploy your .NET applications to AWS in just a few simple clicks? Try our new .NET CLI tooling for a simplified deployment experience! Read our blog post and submit your feedback on GitHub!

For additional information, see the section for the deployment tool in this guide.

Seeing your Amazon EC2 Regions and Availability Zones

Amazon EC2 is hosted in multiple locations worldwide. These locations are composed of Regions and Availability Zones. Each Region is a separate geographic area that has multiple, isolated locations known as Availability Zones.

Read more about Regions and Availability Zones in the EC2 user guide for Linux or the EC2 user guide for Windows.

This example shows you how to use the AWS SDK for .NET to get details about the Regions and Availability Zones related to an EC2 client. The application displays lists of the Regions and Availability Zones available to an EC2 client.

NuGet packages:

Programming elements:

using System; using System.Threading.Tasks; using Amazon.EC2; using Amazon.EC2.Model; namespace EC2RegionsAndZones { class Program { static async Task Main(string[] args) { Console.WriteLine( "Finding the Regions and Availability Zones available to an EC2 client..."); // Create the EC2 client var ec2Client = new AmazonEC2Client(); // Display the Regions and Availability Zones await DescribeRegions(ec2Client); await DescribeAvailabilityZones(ec2Client); } // // Method to display Regions private static async Task DescribeRegions(IAmazonEC2 ec2Client) { Console.WriteLine("\nRegions that are enabled for the EC2 client:"); DescribeRegionsResponse response = await ec2Client.DescribeRegionsAsync(); foreach (Region region in response.Regions) Console.WriteLine(region.RegionName); } // // Method to display Availability Zones private static async Task DescribeAvailabilityZones(IAmazonEC2 ec2Client) { Console.WriteLine("\nAvailability Zones for the EC2 client's region:"); DescribeAvailabilityZonesResponse response = await ec2Client.DescribeAvailabilityZonesAsync(); foreach (AvailabilityZone az in response.AvailabilityZones) Console.WriteLine(az.ZoneName); } } }