Matching EC2 Availability Zones Across AWS Accounts

| 6 Comments

Summary: EC2 availability zone names in different accounts do not match to the same underlying physical infrastructure. This article explains a trick which can be used to figure out how to match availability zone names between different accounts.

Background

As of the updating of this article (2011-12-23) Amazon EC2 (Elastic Compute Cloud) has twenty different availability zones in eight regions. A region can be thought of as a specific area of the world. An availability zone can be thought of roughly as a data center, defined such that no single failure scenario should affect two availability zones.

The current regions are:

  • us-east-1 - East coast of the United States (Northern Virginia)
  • us-west-1 - West coast of the United States (Northern California)
  • us-west-2 - West coast of the United States (Oregon)
  • sa-east-1 - East coast of South America (São Paulo, Brazil)
  • eu-west-1 - Western Europe (Dublin, Ireland)
  • ap-southeast-1 - SouthEast Asia (Singapore)
  • ap-northeast-1 - NorthEast Asia (Tokyo)
  • GovCloud - US Government use only

The availability zones in those regions are given the region name plus simple letters appended. For example:

  • us-east-1a
  • us-east-1b
  • us-east-1c
  • us-east-1d

and

  • eu-west-1a
  • eu-west-1b

When you start EC2 instances, you can specify an availability zone or let Amazon pick one for you. You always have a default region which can be overridden when starting instances.

Balancing

In order to prevent an overloading of a single availability zone when everybody tries to run their instances in us-east-1a, Amazon has added a layer of indirection so that each account’s availability zones can map to different physical data center equivalents.

For example, zone us-east-1a in your account might be the same as zone us-east-1c in my account and us-east-1d in a third person’s account.

In fact, given the way that Amazon has set this up, I would not be surprised if Amazon may not occasionally reassign availability zone names which you are not currently using. For example, Amazon added the fourth availability zone in the us-east-1 region, but I suspect this might not be us-east-1d in all accounts (especially new ones).

Identification

On occasion, users sometimes want to know if instances in different accounts are running in the same availability zone. Or, users might want to know which availability zone is the one with which people are currently experiencing a particular problem.

You’ll often see users say that there is a problem in zone us-east-1a but this isn’t very helpful for other users because (as described above) that name only has significance within the original user’s account.

What would be helpful is a unique identifier which maps to the underlying physical infrastructure (e.g., data center) and can be mapped to the different availability zone names in each account.

I believe that Amazon may have inadvertently let slip a way to obtain this in the current implementation of the reserved instance offering ids. In my experiments so far, these seem to be tied to something outside of the account’s availability zones and, though the ids are the same, they are mapped to different availability zone names for different accounts.

To demonstrate this I’ve arbitrarily chosen the reserved instance offerings for m1.small, one year, Linux/UNIX.

To list the mappings for a single account, you can use a command like:

ec2-describe-regions | cut -f2 | while read region; do 
  ec2-describe-reserved-instances-offerings --region $region | 
    perl -ne 'print "$2 $1\n" if 
     m%\S+\t(\S+)\t(\S+)\tm1.small\t1y.\t.*\tLinux/UNIX(\t(.(?!Utilization)|Medium Utilization)*)$%'
done | sort

Examples

Here are the mappings for one of my accounts (let’s call it “Blue”):

ap-northeast-1a 4b2293b4-ed86-4e9c-a41d-b9aa6ab6d143 
ap-northeast-1b ceb6a579-a3ba-4488-ae42-59ca92a3d26f
ap-southeast-1a d586503b-ce55-4e1e-8012-f87395ccfb39
ap-southeast-1b 649fd0c8-66cb-4867-a124-70e7b38902b1
eu-west-1a c48ab04c-0bd0-4be9-8db5-a4bad61c6c58
eu-west-1b d586503b-7025-44e8-8487-09907b6b0e7e
eu-west-1c c48ab04c-ca5b-43be-999b-ed45d67a058e
sa-east-1a ceb6a579-ef87-4741-bbb5-f52911e182b4
sa-east-1b 248e7b75-96bb-4161-b50a-2f042094f022
us-east-1a 438012d3-80c7-42c6-9396-a209c58607f9
us-east-1b 60dcfab3-06bb-4b68-9503-53bf89823b5e
us-east-1c ceb6a579-757c-474b-b09b-52c84b605767
us-east-1d 649fd0c8-5d76-4881-a522-fe5224c10fcc
us-west-1a c48ab04c-446f-416d-b7e1-75db17b1354c
us-west-1b e5a2ff3b-79b4-4217-8c93-ebf1d633dd6e
us-west-1c 4b2293b4-def5-468b-ae97-63886afe7a09
us-west-2a 60dcfab3-d0b1-48f5-bb2a-031bba5ec5e5
us-west-2b ceb6a579-9c3b-4098-b745-c3e256d612c5

Here are the mappings for a different account (let’s call it “Red”):

ap-northeast-1a 4b2293b4-ed86-4e9c-a41d-b9aa6ab6d143
ap-northeast-1b ceb6a579-a3ba-4488-ae42-59ca92a3d26f
ap-southeast-1a 649fd0c8-66cb-4867-a124-70e7b38902b1
ap-southeast-1b d586503b-ce55-4e1e-8012-f87395ccfb39
eu-west-1a d586503b-7025-44e8-8487-09907b6b0e7e
eu-west-1b c48ab04c-0bd0-4be9-8db5-a4bad61c6c58
eu-west-1c c48ab04c-ca5b-43be-999b-ed45d67a058e
sa-east-1a 248e7b75-96bb-4161-b50a-2f042094f022
sa-east-1b ceb6a579-ef87-4741-bbb5-f52911e182b4
us-east-1a ceb6a579-757c-474b-b09b-52c84b605767
us-east-1b 438012d3-80c7-42c6-9396-a209c58607f9
us-east-1c 60dcfab3-06bb-4b68-9503-53bf89823b5e
us-east-1d 649fd0c8-5d76-4881-a522-fe5224c10fcc
us-west-1a e5a2ff3b-79b4-4217-8c93-ebf1d633dd6e
us-west-1b c48ab04c-446f-416d-b7e1-75db17b1354c
us-west-1c 4b2293b4-def5-468b-ae97-63886afe7a09
us-west-2a 60dcfab3-d0b1-48f5-bb2a-031bba5ec5e5
us-west-2b ceb6a579-9c3b-4098-b745-c3e256d612c5

From this, I theorize that availability zone us-east-1a in account Blue is the same as availability zone us-east-1b in account Red, but availability zones us-east-1d happen to be the same in both accounts.

Caveats

Please note that this approach is not a documented feature of Amazon EC2. I may be misinterpreting what I am seeing and the mappings may be completely random for different accounts.

Amazon could at any time restructure how these values work so that the described offering ids cannot be used between accounts or do not map to any common infrastructure.

Use at your own risk and please post a comment if you find out any further data to support or disprove this theory.

[Update 2011-04-25: Tweaked command line to exclude more instance types Amazon has added. Updated info for current ids in current regions/zones.] [Update 2011-12-23: Tweaked command line to exclude more instance types Amazon has added. Updated info for current ids in current regions/zones.]

6 Comments

Awesome - thanks!

This can help eliminate cross-availability-zone networking charges when I copy data from my Testing account to/from my Production account. In order to restrict access to the Production deployment I have two separate AWS accounts, Testing and Production. The AZs in these accounts do not match, and I sometimes end up being charged for transferring data between (instances belonging to) the two accounts. Using your tip I can figure out where to deploy my Testing instances to save $$ transferring data between instances belonging to the different accounts.

As of Dec. 20, 2012 it looks like Amazon has changed their zones mapping again. Now for each zone they have multiple codes. Below are few output lines from one of my EC2 accounts:

ap-northeast-1a 3a98bf7d-8adc-4dfe-9bd6-b16a735c0894
ap-northeast-1a 4b2293b4-ed86-4e9c-a41d-b9aa6ab6d143
ap-northeast-1a d586503b-1ff7-4466-8593-34b02b42d768
ap-northeast-1b 4b2293b4-8b7a-4aec-9636-cc4aad7e3514
ap-northeast-1b ceb6a579-9e28-422a-ac6b-d200348f1ea1
ap-northeast-1b ceb6a579-a3ba-4488-ae42-59ca92a3d26f

Yiftach:

Thanks. I have updated the code above to only look for "Medium Utilization" records (the previous default).

Another approach to the same problem (though definitely a more complex approach) would be to use the spot instance pricing history. The history can be used as a signature to match azs across accounts -- histories rarely match between azs in the same region with even the 1 day timeframe (exception being us-west-2/Oregon).

Also worth noting -- this is a guess -- I haven't tried it in practice yet. Maybe I'll find that spot rates differ between accounts in the same datacenter/ configuration.

Do you mind telling users who are unfamiliar with commands such as "ec2-describe-regions" where one can obtain those commands. I've tried running them on my ec2 instance to no avail.

hengjie:

You can install these commands on Ubuntu using:

sudo apt-get install ec2-api-tools

You'll also need to set up the AWS credentials and some environment variables as described here: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/setting-up-your-tools.html#set-aes-home

Leave a comment

Ubuntu AMIs

Ubuntu AMIs for EC2:


More Entries

EC2 create-image Does Not Fully "Stop" The Instance
The EC2 create-image API/command/console action is a convenient trigger to create an AMI from a running (or stopped) EBS boot instance. It takes a snapshot of the instance’s EBS volume(s)…
Finding the Region for an AWS Resource ID
use concurrent AWS command line requests to search the world for your instance, image, volume, snapshot, … Background Amazon EC2 and many other AWS services are divided up into various…
Changing The Default "ubuntu" Username On New EC2 Instances
configure your own ssh username in user-data The official Ubuntu AMIs create a default user with the username ubuntu which is used for the initial ssh access, i.e.: ssh ubuntu@<HOST>…
Default ssh Usernames For Connecting To EC2 Instances
Each AMI publisher on EC2 decides what user (or users) should have ssh access enabled by default and what ssh credentials should allow you to gain access as that user.…
New c3.* Instance Types on Amazon EC2 - Nice!
Worth switching. Amazon shared that the new c3.* instance types have been in high demand on EC2 since they were released. I finally had a minute to take a look…
Query EC2 Account Limits with AWS API
Here’s a useful tip mentioned in one of the sessions at AWS re:Invent this year. There is a little known API call that lets you query some of the EC2…
Using aws-cli --query Option To Simplify Output
My favorite session at AWS re:Invent was James Saryerwinnie’s clear, concise, and informative tour of the aws-cli (command line interface), which according to GitHub logs he is enhancing like crazy.…
Reset S3 Object Timestamp for Bucket Lifecycle Expiration
use aws-cli to extend expiration and restart the delete or archive countdown on objects in an S3 bucket Background S3 buckets allow you to specify lifecycle rules that tell AWS…
Installing aws-cli, the New AWS Command Line Tool
consistent control over more AWS services with aws-cli, a single, powerful command line tool from Amazon Readers of this tech blog know that I am a fan of the power…
Using An AWS CloudFormation Stack To Allow "-" Instead Of "+" In Gmail Email Addresses
Launch a CloudFormation template to set up a stack of AWS resources to fill a simple need: Supporting Gmail addresses with “-” instead of “+” separating the user name from…
New Options In ec2-expire-snapshots v0.11
The ec2-expire-snapshots program can be used to expire EBS snapshots in Amazon EC2 on a regular schedule that you define. It can be used as a companion to ec2-consistent-snapshot or…
Replacing a CloudFront Distribution to "Invalidate" All Objects
I was chatting with Kevin Boyd (aka Beryllium) on the ##aws Freenode IRC channel about the challenge of invalidating a large number of CloudFront objects (35,000) due to a problem…
Email Alerts for AWS Billing Alarms
using CloudWatch and SNS to send yourself email messages when AWS costs accrue past limits you define The Amazon documentation describes how to use the AWS console to monitor your…
Cost of Transitioning S3 Objects to Glacier
how I was surprised by a large AWS charge and how to calculate the break-even point Glacier Archival of S3 Objects Amazon recently introduced a fantastic new feature where S3…
Running Ubuntu on Amazon EC2 in Sydney, Australia
Amazon has announced a new AWS region in Sydney, Australia with the name ap-southeast-2. The official Ubuntu AMI lookup pages (1, 2) don’t seem to be showing the new location…
Save Money by Giving Away Unused Heavy Utilization Reserved Instances
You may be able to save on future EC2 expenses by selling an unused Reserved Instance for less than its true value or even $0.01, provided it is in the…
Installing AWS Command Line Tools from Amazon Downloads
When you need an AWS command line toolset not provided by Ubuntu packages, you can download the tools directly from Amazon and install them locally. In a previous article I…
Convert Running EC2 Instance to EBS-Optimized Instance with Provisioned IOPS EBS Volumes
Amazon just announced two related features for getting super-fast, consistent performance with EBS volumes: (1) Provisioned IOPS EBS volumes, and (2) EBS-Optimized Instances. Starting new instances and EBS volumes with…
Which EC2 Availability Zone is Affected by an Outage?
Did you know that Amazon includes status messages about the health of availability zones in the output of the ec2-describe-availability-zones command, the associated API call, and the AWS console? Right…
Installing AWS Command Line Tools Using Ubuntu Packages
See also: Installing AWS Command Line Tools from Amazon Downloads Here are the steps for installing the AWS command line tools that are currently available as Ubuntu packages. These include:…
Ubuntu Developer Summit, May 2012 (Oakland)
I will be attending the Ubuntu Developer Summit (UDS) next week in Oakland, CA.  This event brings people from around the world together in one place every six months to…
Uploading Known ssh Host Key in EC2 user-data Script
The ssh protocol uses two different keys to keep you secure: The user ssh key is the one we normally think of. This authenticates us to the remote host, proving…
Seeding Torrents with Amazon S3 and s3cmd on Ubuntu
Amazon Web Services is such a huge, complex service with so many products and features that sometimes very simple but powerful features fall through the cracks when you’re reading the…
CloudCamp
There are a number of CloudCamp events coming up in cities around the world. These are free events, organized around the various concepts, technologies, and services that fall under the…
Use the Same Architecture (64-bit) on All EC2 Instance Types
A few hours ago, Amazon AWS announced that all EC2 instance types can now run 64-bit AMIs. Though t1.micro, m1.small, and c1.medium will continue to also support 32-bit AMIs, it…
ec2-consistent-snapshot on GitHub and v0.43 Released
The source for ec2-conssitent-snapshot has historically been available here: ec2-consistent-snapshot on Launchpad.net using Bazaar For your convenience, it is now also available here: ec2-consistent-snapshot on GitHub using Git You are…
You Should Use EBS Boot Instances on Amazon EC2
EBS boot vs. instance-store If you are just getting started with Amazon EC2, then use EBS boot instances and stop reading this article. Forget that you ever heard about instance-store…
Retrieve Public ssh Key From EC2
A serverfault poster had a problem that I thought was a cool challenge. I had so much fun coming up with this answer, I figured I’d share it here as…
Running EC2 Instances on a Recurring Schedule with Auto Scaling
Do you want to run short jobs on Amazon EC2 on a recurring schedule, but don’t want to pay for an instance running all the time? Would you like to…
AWS Virtual MFA and the Google Authenticator for Android
Amazon just announced that the AWS MFA (multi-factor authentication) now supports virtual or software MFA devices in addition to the physical hardware MFA devices like the one that’s been taking…