Sub topic 2
Accounts, Regions, and identities
This chapter assumes you have an AWS account to sign in to, a working terminal, and a rough idea of what a cloud service is. Everything you do in the Console, the CLI, or CloudShell depends on three questions: which account you are in, which Region you are talking to, and which identity you are acting as. When a command fails or a resource seems to be missing, the cause is usually one of these three.
The account: AWS's basic boundary
An AWS account is a container for resources and the unit that AWS bills. It has a 12-digit account ID such as 111122223333 (a placeholder used throughout this tutorial). Resources in one account are isolated from other accounts by default. Access across accounts has to be granted on purpose.
Many organizations use several accounts instead of one, for example one each for development, testing, and production. AWS Organizations groups accounts under a single management account. It provides consolidated billing and lets administrators apply guardrails across accounts. As a day-to-day user you mostly see this as a list of accounts and roles to choose from when you sign in.
An account is not a person. People and programs act inside an account through identities.
Regions and Availability Zones
A Region is a separate geographic area where AWS runs data centers, such as us-east-1 (N. Virginia) or eu-west-1 (Ireland). Each Region is independent. Most resources you create live in exactly one Region, and each Region has its own endpoints, such as ec2.eu-west-1.amazonaws.com.
Each Region has several Availability Zones (AZs). An AZ is one or more data centers with independent power and networking, named like eu-west-1a. You choose AZs when you place resources such as EC2 instances or subnets. You choose the Region first.
Three facts about Regions cause most beginner confusion:
- Resources do not appear across Regions. An EC2 instance in
eu-west-1is invisible if the Console or CLI is pointed atus-east-1. The resource still exists, and you are looking in the wrong place. - Some Regions are opt-in. Newer Regions are disabled until an account administrator enables them. Calls to a disabled Region fail.
- Some services are global or have a global view. IAM, for example, is not tied to a Region. Amazon S3 is mixed: bucket names are globally unique, but each bucket lives in one Region.
You can list the Regions your account can currently use:
aws ec2 describe-regions --query 'Regions[].RegionName' --output textAdd --all-regions to include opt-in Regions that are not yet enabled.
How the CLI picks a Region
For a regional service, the CLI needs a Region on every call. It looks in this order and uses the first one it finds:
- The
--regionoption on the command. - The
AWS_DEFAULT_REGIONenvironment variable. - The
regionsetting of the active profile in~/.aws/config.
If none is set, the call fails with an error such as You must specify a region. The Console works differently. It keeps a Region selector in the top bar, and the selected Region applies to every regional service page until you change it.
Identities: who is making the request
An identity is the entity AWS authenticates and then authorizes. AWS first checks who you are, then checks whether a policy allows the action you attempted. This section covers the identity types you will meet.
The root user
When you create an account, you get a root user, which signs in with the account's email address and a password. The root user has unrestricted access to everything in the account, and IAM policies cannot limit it. Use it only for the few tasks that require it, such as changing account settings or closing the account. Protect it with multi-factor authentication (MFA) and do not create access keys for it. Chapter "Keeping access secure" returns to this.
IAM users
An IAM user is a long-lived identity that belongs to one account. It can have a console password and, optionally, access keys for the CLI. Access keys are an access key ID plus a secret access key, and they do not expire until you delete or deactivate them. That makes them convenient and risky: a leaked key works from anywhere until someone revokes it.
IAM roles
An IAM role is an identity with permissions but no password and no permanent keys. Something assumes the role and receives temporary credentials from AWS Security Token Service (STS). The credentials include a session token and expire, commonly within an hour. Roles are used by people (to switch into another account), by AWS services (an EC2 instance acting on your behalf), and by programs.
IAM Identity Center
IAM Identity Center is the recommended way for people to sign in to one or many accounts. You sign in once at an access portal, pick an account and a permission set, and receive a role session with temporary credentials. The CLI can use this flow too, so no long-lived keys are stored on your machine. The chapter on signing in to the CLI covers the commands.
Comparing the options
| Identity | Credentials | Lifetime | Typical use |
|---|---|---|---|
| Root user | Email and password, MFA | Until changed | Rare account-level tasks |
| IAM user | Password, access keys | Long-lived | Legacy setups, narrow cases |
| IAM role | Temporary STS credentials | Minutes to hours | Services, cross-account access, federated people |
| IAM Identity Center user | Portal sign-in, role sessions | Short sessions | Day-to-day human access |
How the pieces fit together
Checking who you are and where you are
Before changing anything, confirm your identity. The same command works in the CLI and in CloudShell:
aws sts get-caller-identityThe output has three fields: UserId, Account, and Arn. An example for a role session obtained through IAM Identity Center looks like this:
{
"UserId": "AROAEXAMPLEID:alice",
"Account": "111122223333",
"Arn": "arn:aws:sts::111122223333:assumed-role/ReadOnly/alice"
}The ARN (Amazon Resource Name) tells you the type. assumed-role means a role session. An IAM user shows user/name, and the root user shows root. This call needs no special permissions, so it works even when everything else is denied.
To see which Region the CLI will use, ask for the effective configuration:
aws configure listThis prints the resolved profile, credentials source, and Region, and shows where each value came from (env, config-file, manual, and so on). Use --profile to inspect a named profile.
Common mistakes
- Looking in the wrong Region. If a bucket, instance, or stack seems to have vanished, check the Region selector in the Console, or add
--regionto the CLI command. Compare against the Region where you created it. - Working in the wrong account. Names like "dev" and "prod" may both appear in your portal. Run
aws sts get-caller-identityand compare theAccountvalue with the one you intend. - Using the root user for routine work. Sign in with a role or an Identity Center user instead.
- Assuming a global service needs a Region. IAM calls succeed regardless of Region, but the CLI may still want a Region configured to sign requests. Setting a default Region in your profile avoids the question.
- Forgetting opt-in Regions. If a Region is missing from
describe-regions, an administrator may need to enable it first.
Exercise
You created an S3 bucket last week and an EC2 instance in eu-west-1 yesterday. Today aws ec2 describe-instances returns an empty list, and aws sts get-caller-identity shows the correct account. What is the most likely cause, and which two ways can you fix it for one command?
Show answer
The CLI is using a different Region (for example us-east-1 from the profile default), and EC2 instances are regional, so the instance is not visible there. Fix it for one command by adding --region eu-west-1, or by setting AWS_DEFAULT_REGION=eu-west-1 in the environment for that command. You could also change the region value in the profile.
Exercise
What does the ARN arn:aws:sts::111122223333:assumed-role/ReadOnly/alice tell you about the identity, compared with an ARN ending in :root?
Show answer
It is a temporary role session for the role ReadOnly in account 111122223333, with session name alice. It has only the permissions of that role and its credentials expire. An ARN ending in :root is the account's root user, which has unrestricted access and should be reserved for rare account-level tasks.