AWS SDK for .NET
Developer Guide

Using Regions and Availability Zones with Amazon EC2

This .NET example shows you how to:

  • Get details about Availability Zones

  • Get details about regions

The Scenario

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. Amazon EC2 provides the ability to place instances and data in multiple locations.

You can use the AWS SDK for .NET to retrieve details about regions and Availability Zones by using the following methods of the AmazonEC2Client class:

For more information about regions and Availability Zones, see Regions and Availability Zones in the Amazon EC2 User Guide for Windows Instances.

Describe Availability Zones

Create an AmazonEC2Client instance and call the DescribeAvailabilityZones method. The DescribeAvailabilityZonesResponse object that is returned contains a list of Availability Zones.

public static void DescribeAvailabilityZones() { Console.WriteLine("Describe Availability Zones"); AmazonEC2Client client = new AmazonEC2Client(); DescribeAvailabilityZonesResponse response = client.DescribeAvailabilityZones(); var availZones = new List<AvailabilityZone>(); availZones = response.AvailabilityZones; foreach (AvailabilityZone az in availZones) { Console.WriteLine(az.ZoneName); } }

Describe Regions

Create an AmazonEC2Client instance and call the DescribeRegions method. The DescribeRegionsResponse object that is returned contains a list of regions.

public static void DescribeRegions() { Console.WriteLine("Describe Regions"); AmazonEC2Client client = new AmazonEC2Client(); DescribeRegionsResponse response = client.DescribeRegions(); var regions = new List<Region>(); regions = response.Regions; foreach (Region region in regions) { Console.WriteLine(region.RegionName); } }