Reputation: 137
When configuring the lightsail client, it asks me to provide a region, if I don't provide a region, requests don't go through.
However, providing a region only gives me availability zones associated with that region even though the code gives me all regions anyways. If this were the case, it would make more sense to just provide the client's region in the response, but I get them all which is odd that it is not consistent with the data provided in terms of availability zones. Here is the below code that I'm testing to retrieve the availability zones which I plan to store and use at a further point in the application.
AWSCredentials credentials = new BasicAWSCredentials("[redacted]", "[redacted]");
AmazonLightsailClient client = new AmazonLightsailClient(credentials, RegionEndpoint.USEast1);
var response = await client.GetRegionsAsync(new GetRegionsRequest() { IncludeAvailabilityZones = true});
foreach (Region currentRegion in response.Regions)
{
Console.WriteLine($"Region {currentRegion.Name} - {currentRegion.AvailabilityZones.Count} availability zones");
}
The output is shown below
Without having to resort to looping through all RegionEndpoints and instantiating a new client in that Region, is there a way I can just get all availability zones when it provides all Regions or am I going to have to waste 1 API call per region to get this data?
Upvotes: 0
Views: 659
Reputation: 21
You just need to change the region in your api client settings. This is a different SDK to yours, but equivalent to your C++ version.
$client= new $class([
'profile' => 'default',
'region' => us-east-1,
'version' => 'latest',
]);
and when you call using either: $result = $client->describeAvailabilityZones(); or $result = $client->getRegions([]);
You'll get visibility and access to the availability zones in that region.
Unfortunately it's not possible to get a list or create instances, without changing the api client's region.
If you're just looking to get a complete list for reference, you'll have to loop the call, changing the region based on the known set of regions you have enabled for your account (as not all AWS regions are automatically enabled).
Upvotes: 0
Reputation: 65702
I'm not sure about LightSail but you can use the SDK to do these EC2 Commands to query all Regions (some regions have null for AZ Count, either they're under construction or something has changed with the API):
aws ec2 describe-regions --query 'Regions[*].{RegionName:RegionName, AvailabilityZoneCount:AvailabilityZoneCount}'
[
{
"RegionName": "ap-south-1",
"AvailabilityZoneCount": null
},
{
"RegionName": "eu-north-1",
"AvailabilityZoneCount": null
},
{
"RegionName": "eu-west-3",
Then query individual Regions to get info about the Zones (I'm using ap-southeast-2):
aws ec2 describe-availability-zones --region ap-southeast-2 --query 'AvailabilityZones[*].{ZoneName:ZoneName}'
[
{
"ZoneName": "ap-southeast-2a" },
{
"ZoneName": "ap-southeast-2b" },
{
"ZoneName": "ap-southeast-2c" } ]
Tested:
Upvotes: 1