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.
To read more about Regions and Availability Zones, see Regions and Zones in the Amazon EC2 User Guide.
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:
-
Namespace Amazon.EC2
Class AmazonEC2Client
-
Namespace Amazon.EC2.Model
Class DescribeAvailabilityZonesResponse
Class DescribeRegionsResponse
Class AvailabilityZone
Class Region
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); } } }