AWS Account and Console
Everything you build on AWS belongs to an AWS account: a container for resources, a security boundary and a billing unit, identified by a 12-digit account ID such as 123456789012.
Creating an account
Signing up needs an email address, a payment method and a phone number for verification. The email address and password you sign up with become the root user, which can do anything in the account, including closing it.
Immediately after signing up:
- Turn on MFA (multi-factor authentication) for the root user.
- Create an everyday administrator identity (with IAM Identity Center or an IAM user) and stop using root.
- Create a budget alert so a forgotten resource can't surprise you (see the pricing lesson).
Tip: Many services have a Free Tier for new accounts or small usage. It has limits; resources beyond them are billed normally.
Three ways to talk to AWS
| Interface | Best for |
|---|---|
| AWS Management Console (web UI) | Learning, exploring, one-off tasks |
AWS CLI (aws ... in a terminal) |
Scripts, automation, repeatable tasks |
| SDKs (boto3 for Python, SDKs for JS, Java, Go, ...) | Calling AWS from your own applications |
All three end up making the same signed HTTPS API calls. Infrastructure-as-code tools such as CloudFormation (covered later) sit on top of these APIs too.
Configuring the CLI
aws configure --profile learnerSample output (you type the values after each prompt):
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: eu-west-1
Default output format [None]: jsonThe values are stored in two plain-text files in your home directory:
# ~/.aws/credentials
[learner]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
# ~/.aws/config
[profile learner]
region = eu-west-1
output = jsonModel: how the CLI finds its settings
The CLI and SDKs search for configuration in a fixed order and use the first value found. This model mimics the order for the region setting:
def resolve_region(cli_flag=None, env=None, profile_config=None, default_profile=None):
sources = [
("--region flag", cli_flag),
("AWS_REGION / AWS_DEFAULT_REGION env var", (env or {}).get("AWS_REGION") or (env or {}).get("AWS_DEFAULT_REGION")),
("profile in ~/.aws/config", profile_config),
("[default] profile", default_profile),
]
for name, value in sources:
if value:
return value, name
return None, "not set: the command fails with 'You must specify a region'"
print(resolve_region(cli_flag="us-east-1", env={"AWS_REGION": "eu-west-1"}))
print(resolve_region(env={"AWS_DEFAULT_REGION": "eu-central-1"}, profile_config="eu-west-1"))
print(resolve_region(profile_config="ap-south-1", default_profile="us-west-2"))
print(resolve_region())('us-east-1', '--region flag')
('eu-central-1', 'AWS_REGION / AWS_DEFAULT_REGION env var')
('ap-south-1', 'profile in ~/.aws/config')
(None, "not set: the command fails with 'You must specify a region'")
A surprising region is a classic beginner problem: "my instance disappeared!" usually means the console or CLI is looking at a different Region.
Model: spotting access keys that should not exist
Access keys are long-lived passwords for the API. AWS key IDs have recognisable prefixes: AKIA for long-term IAM user keys and ASIA for temporary credentials from STS. A check like this helps find keys accidentally committed to source code:
import re
KEY_ID = re.compile(r"\b(AKIA|ASIA)[A-Z0-9]{16}\b")
files = {
"app/config.py": 'BUCKET = "tad-media"\nKEY = "AKIAIOSFODNN7EXAMPLE"\n',
"README.md": "Run `aws configure` and paste your own key.\n",
"deploy.sh": "export AWS_ACCESS_KEY_ID=ASIAY34FZKBOKMUTVV7A\n",
}
for path, text in files.items():
for lineno, line in enumerate(text.splitlines(), start=1):
for m in KEY_ID.finditer(line):
kind = "long-term user key" if m.group(1) == "AKIA" else "temporary STS key"
print(f"{path}:{lineno}: {m.group(0)} ({kind})")app/config.py:2: AKIAIOSFODNN7EXAMPLE (long-term user key)
deploy.sh:1: ASIAY34FZKBOKMUTVV7A (temporary STS key)
Note: The safest access key is one that doesn't exist. Prefer IAM roles and temporary credentials (IAM Identity Center for people, roles for EC2 and Lambda), covered in the IAM lessons.
Test yourself
What should you do with the root user right after creating an account?
- Use it for daily work
- Enable MFA and stop using it for daily tasks
- Delete it
- Share it with the team
Which value wins when both --region us-east-1 and AWS_REGION=eu-west-1 are set?
- eu-west-1
- us-east-1
- The default profile
- An error
Which tool is best suited for calling AWS from your own Python application?
- The console
- boto3, the AWS SDK for Python
- AWS Artifact
- A CloudFront distribution