Skip to main content

Getting started with AWS

Published

2026-12-02

This chapter covers creating AWS users and groups, attaching policies, creating access keys, and configuring the AWS command line interface (CLI).

AWS set up

First, you’ll need to log into AWS. This is separate from your regular Amazon account, and comes with different tiers. I highly recommend turning on the MFA and using something like the Microsoft Authenticator app to login.

When you first access AWS, your landing page will look something like this:

AWS Console

AWS Console

This is your AWS Console, where you’ll launch new instances, select storage devices, containers, etc. We’ll start with Identity and Access Management (IAM) in the Console. Then we’ll install and configure the AWS CLI.

Identity and Access Management (IAM)

Back in the AWS Console, we need to create a group, attach policies to this group, then create a user.

Creating Groups

In the AWS Console, we’ll navigate to:

IAM > IAM User groups > Create group

Look for IAM in ‘Recently visited’

Look for IAM in ‘Recently visited’

Select ‘IAM user groups’

Select ‘IAM user groups’

Give the group a meaningful name: dev-deploy-group

Under Attach permissions policies, search and select the following:

  • AmazonEC2FullAccess
  • AmazonS3FullAccess

Down the road, we should replace these with scoped custom policies later, but for now it will get us up and running.

Click Create Group and you should see something like:

As we can see, this group doesn’t have any users, so we’ll create and add them next.

Creating Users

Back in AWS Console, we’ll navigate to:

IAM Users > Create User

We’ll give the user a meaningful username: mjfrigaard-cli

Create IAM user

Create IAM user

We have the option to check “Provide user access to the AWS Management Console”. Right now mjfrigaard-cli only needs the CLI, so we’ll leave it unchecked and give the user only the access it uses. A user without a Console password can’t sign in to the Console, so there’s one less credential to protect. We can turn Console access on later without recreating the user (see Console access for mjfrigaard-cli).

Now, under Add user to group, we select dev-deploy-group and click Next

Add user to group

Add user to group

At this point, we’re given a chance to review our selections before confirming, which is also a great opportunity to quickly cover AWS IAM users and groups.

Review user/group selections

Review user/group selections

IAM: Core concepts

AWS IAM is somewhat like Linux users and groups, but instead of file permissions, IAM uses policies to control who can do what, and where. Three core concepts to know about AWS IAM:

  1. A user is an identity (a person or a service).1
  2. A group is a collection of users that share permissions.2
  3. A policy is a JSON document that says what actions are allowed on what resources3

Users don’t get permissions directly, they inherit permissions from the groups they belong to. If you’ve worked with Linux groups and file permissions before, the table below might be helpful for mapping the AWS IAM concepts.

AWS IAM concept Linux user/groups analog
IAM User User
IAM Group Group
IAM Policy (JSON file) File permissions (rwx)
IAM Users list /etc/passwd
Elevated permissions granted by attached policy sudo
Access via access key ID + secret access key SSH keys

So far, we’ve created or logged into our AWS account. Then, from the AWS Console, we 1) created an IAM group, 2) attached IAM policies to the IAM group, 3) created an IAM user, and 4) assigned that user to the IAM group.

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph TD
    AWS(["AWS<br>Account"]) --"create"--> Groups("IAM Groups")
    AWS --"create"--> Users("IAM Users")
    Policy[/"IAM Policies"/]

    Policy --"attach"--> Groups
    Groups --"inherit"--> Users
    
    style Policy fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style AWS fill:#E8A33D,stroke:#000000,stroke-width:1px,color:#ffffff
    style Groups fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style Users fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    

IAM users, groups, and policies

Policies determine permissions

For example, say we have a new developer, Alice (alice). Alice wouldn’t get any permissions herself, but she’d be a member of the devs group, which has a S3ReadWrite policy attached, which allows Alice access to the my-data bucket.

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph LR

    Policy[/"Policy:<br><code>S3ReadWrite</code>"/]
    Groups("IAM Group:<br><code>devs</code>")
    Users("IAM User:<br><code>alice</code>")
    Resource[("S3 Bucket:<br><code>my-data</code>")]
    
    Policy --> Groups --> Users --> Resource
    
    style Policy fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style Resource fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    style Groups fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style Users fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    

Policies and permissions

A policy is like a permissions file. It specifies an effect (allow or deny), an action (what operation, like s3:PutObject), and the resource (what it applies to, i.e., a specific bucket).4

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph LR
    Policy[/"Policy<br>Document"/] --> Effect("<strong>Effect</strong>:<br><em>Allow</em>")
    Policy --> Action("<strong>Action:</strong><br><em>s3:PutObject</em>")
    Policy --> Resource[("<strong>Resource:</strong><br><em>arn:aws:s3:::my-bucket/*</em>")]
    
    style Policy fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style Effect fill:#3E2A1E,stroke:#000000,stroke-width:1px,color:#ffffff
    style Action fill:#3E2A1E,stroke:#000000,stroke-width:1px,color:#ffffff
    style Resource fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    

Policy effects, actions, and resources

What about multiple groups?

Like a Linux user being in multiple groups (sudo, docker, www-data), an IAM user can belong to multiple IAM groups. Consider the user alice below:

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%


graph TD

    Users(["<strong>alice</strong>"]) --"In Group"--> DevGroup("<strong>devs</strong>")
    Users --"In Group"--> OpsGroup("<strong>ops</strong>")

    DevGroup --> S3Policy[/"<strong>Policy</strong>:<br><em>S3 Access</em>"/]
    OpsGroup --> EC2Policy[/"<strong>Policy</strong>:<br><em>EC2 Access</em>"/]

    S3Policy --> S3[("S3<br>Buckets")]
    EC2Policy --> EC2["EC2<br>Instances"]
    
    
    style Users fill:#2A6F77,stroke:#000000,stroke-width:1px,font-size:14px,text-align:center,font-family:monospace,color:#ffffff
    
    style DevGroup fill:#1B2A41,stroke:#000000,stroke-width:1px,font-size:14px,text-align:center,font-family:monospace,color:#ffffff
    style OpsGroup fill:#1B2A41,stroke:#000000,stroke-width:1px,font-size:14px,text-align:center,font-family:monospace,color:#ffffff
    
    style S3Policy fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style EC2Policy fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff

    style S3 fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    style EC2 fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    

Multiple IAM groups

Alice ends up with the combined permissions of both devs and ops groups (just like a Linux user inheriting from multiple group memberships).

Identities

In AWS, identities can be human users (i.e., people like alice logging in via console or CLI). But identities can also be service/automation users, which are things like GitHub Actions or applications that need programmatic access (like a system account or a service account key).

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph TD

    AWS(["AWS<br>Account"]) --"IAM User<br>(human)"--> Human("<strong>alice</strong>")
    AWS --"IAM User<br>(service)"--> Service("<strong>gha-bot</strong>")

    Human --> ConsoleAccess["Console Login +<br> CLI Keys"]
    Service --> Keys["Access Keys Only,<br>No Console"]
    
    style AWS fill:#E8A33D,stroke:#000000,stroke-width:1px,color:#ffffff
    
    style Human fill:#2A6F77,stroke:#000000,stroke-width:1px,font-size:14px,text-align:center,font-family:monospace,color:#ffffff
    style Service fill:#2A6F77,stroke:#000000,stroke-width:1px,font-size:14px,text-align:center,font-family:monospace,color:#ffffff
    
    style ConsoleAccess fill:#3E2A1E,stroke:#000000,stroke-width:1px,color:#ffffff
    style Keys fill:#3E2A1E,stroke:#000000,stroke-width:1px,color:#ffffff

    

Humans and services

IAM: Recap

Below is a full picture of IAM users, groups, policies and resources. We’ll be using all of these to stand up an EC2 instance, put our model data into an S3 bucket, and give GitHub Actions access to that bucket.

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph TD

    AWS(["AWS<br>Account"])

    AWS --> Users("IAM Users")
    AWS --> Groups("IAM Groups")
    AWS --> Policies[/"IAM Policies"/]
    AWS --> Roles["<em>IAM Roles<br>(optional, for cross<br>service access)</em>"]

    Users --> Groups
    Groups --> Policies
    Roles --> Policies
    Policies --> Resources["AWS Resources:<br>S3, EC2, etc"]
    
    style AWS fill:#E8A33D,stroke:#000000,stroke-width:1px,color:#ffffff
    style Policies fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style Roles fill:#3E2A1E,stroke:#000000,stroke-width:1px,color:#ffffff
    style Groups fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style Users fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    style Resources fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    

IAM users, groups, policies, and roles

IAM Roles (not covered in depth here) are like temporary identities that services assume. For example, an EC2 instance can assume a role to access S3 without any stored credentials. This is the more secure long-term pattern, but access keys are the simpler starting point.

Creating Access Keys

In the IAM users dashboard, we can see:

  1. the dev-deploy-group,
  2. the policies we attached to this group (AmazonEC2FullAccess and AmazonS3FullAccess), and
  3. the new user we just created (mjfrigaard-cli)

In the Summary section, there is an option to Create access key:

IAM users dashboard

IAM users dashboard

We want to click on Create access key under the Security credentials tab. The Use case we want is the Command Line Interface (CLI):

Follow the steps in the documentation (be sure to store the Access Key ID and Secret Access Key pair somewhere safe!).

Next we’ll cover installing the AWS Command Line Interface (CLI) on our local machine. This will allow us to control AWS from the command line.

Install AWS CLI

First we run the standard apt update:

sudo apt update

Next we download the latest version via the official installer:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

Install an unzip utility:

sudo apt install unzip -y

Use unzip on the downloaded awscliv2.zip file:

unzip awscliv2.zip

Finally, we install aws:

sudo ./aws/install

You should see:

You can now run: /usr/local/bin/aws --version

Verify install

aws --version
aws-cli/2.35.15 Python/3.14.5 Linux/7.2.15-76070215-generic exe/x86_64.pop.24

Logging in

Use the aws login command to log in with the Terminal:

aws login

Select a region by pressing Enter:

No AWS region has been configured. The AWS region is the geographic location of
your AWS resources.

If you have used AWS before and already have resources in your account, specify
which region they were created in. If you have not created resources in your
account before, you can pick the region closest to you:
https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html.

You are able to change the region in the CLI at any time with the command "aws
configure set region NEW_REGION".
AWS Region [us-east-1]:

Then the browser opened and I was able to log in as the root user:

Browser confirmation

Browser confirmation

I logged in as root here because it’s the only identity with Console access so far (we skipped Console access when we created mjfrigaard-cli). The root user has unrestricted access to the entire account, so going forward I recommend using the mjfrigaard-cli IAM user and saving root for the few tasks that require it. Signing in as mjfrigaard-cli needs a Console password, which we add in Console access for mjfrigaard-cli. We’ll configure the access keys for mjfrigaard-cli in the CLI Configuration section below.

You might see the following recommendation for logging in:

I used the aws login command from the Terminal, but still needed an Access Key ID and Secret Access Key to configure the dev-deploy profile.

AWS Terminology Review

We’ve just created a new group, user, access key ID, and secret access key. Let’s review these before going forward, because it got confusing for me the first time I completed this lab.

1. What is an ARN?

ARN = Amazon Resource Name. You may have noticed this under the Summary section for the mjfrigaard-cli user:

The ARN is a unique identifier for a specific AWS resource (a user, bucket, instance, policy, etc).5 ARNs are similar to fully qualified file paths, but for AWS resources.

This is how it works:

arn:aws:iam::ACCOUNT_ID:user/mjfrigaard-cli
Part Value Meaning
arn arn Fixed prefix
aws aws Partition (the standard AWS, not something like GovCloud or China)
iam iam Service
(blank) none Region (IAM is global, so it doesn’t specify a region)
ACCOUNT_ID Account ID Which AWS account owns this user
user/mjfrigaard-cli Resource this is an IAM user named mjfrigaard-cli

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph LR
    ARN["ARN"] --"Partition"--> Partition("<strong>aws</strong>")
    ARN --"Service"--> Service("<strong>iam<br>s3<br>ec2</strong>")
    ARN --"Region"--> Region("<strong>us-east-1 </strong>")
    ARN --"Account ID"--> Account("<strong>ACCOUNT_ID</strong>")
    ARN --"Resource Path"--> Resource("<strong>user/mjfrigaard-cli</strong>")
    
    style ARN fill:#E8A33D,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    style Partition fill:#5B8C5A,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    style Region fill:#3E2A1E,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    style Service fill:#1B2A41,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    style Account fill:#2A6F77,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    style Resource fill:#D2562B,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    

Amazon Resource Names (ARNs) uniquely identify AWS resources

In plain English: “IAM user named mjfrigaard-cli in AWS account ACCOUNT_ID.”

Should I keep my ARN a secret?

No. ARNs are not credentials. They are identifiers, similar to a username or a URL. It’s safe to share, log, or put in documentation. It does not grant access by itself (they just identify a resource).

However, you should keep the Access Key ID + Secret Access Key secret, because these are used to authenticate.

2. IAM Account IDs/Aliases

By default, our AWS account is identified with a 12-digit number (called an Account ID). An Account ID is not secret like access keys (alone it can’t grant access to anything), but don’t share it unnecessarily. You may have seen the option to log in with an IAM account alias instead. An account alias is a human-readable name you can set to work in place of the Account ID.

To create an account alias, use the following command:

aws iam create-account-alias --account-alias my-company-name

This adds a second Console sign in URL. The original URL with the Account ID still works:

https://ACCOUNT_ID.signin.aws.amazon.com/console

The new URL uses the alias:

https://my-company-name.signin.aws.amazon.com/console

This is a purely cosmetic change; it doesn’t affect permissions or ARNs.

CLI Configuration

Back in the Terminal, we’re going to configure a dev-deploy profile with the access keys for the IAM user in dev-deploy-group:

aws configure --profile dev-deploy

This will prompt you for:

  1. Access Key ID
  2. Secret Access Key
  3. Region (us-east-1)
  4. Output format (json)

The command above only creates a named credential profile, stored locally in the files below (nothing was sent to AWS yet):

~/.aws/credentials   (keys)
~/.aws/config        (region/output format)

We can test our configuration with:

aws sts get-caller-identity --profile dev-deploy

This asks AWS: “Using these credentials, who am I?”

It returns the following:

{
    "UserId": "USER_ID",
    "Account": "ACCOUNT_ID",
    "Arn": "arn:aws:iam::ACCOUNT_ID:user/mjfrigaard-cli"
}

AWS’s security token service (STS) validated our keys and returned:

  • UserId: unique internal ID for this IAM user (not the access key ID)
  • Account: AWS account number
  • Arn: confirms we are authenticated as mjfrigaard-cli

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%


graph LR
    CLI(["CLI<br>(stored keys)"])
    STS("<strong>get-caller-identity</strong>")
    CLI --"Security<br>Token<br>Service"--> STS
    STS --Returns--> Response("<strong>UserId<br>Account<br>Arn</strong>")
    
    style CLI fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff
    style STS fill:#2A6F77,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#fff
    style Response fill:#D2562B,stroke:#000000,stroke-width:1px,font-size:14px,text-align:left,font-family:monospace,color:#ffffff
    

Checking credentials with STS

This is the standard way to confirm our CLI credentials are valid and check which identity they belong to.

Console access for mjfrigaard-cli

When we created mjfrigaard-cli, we skipped Console access because the user only needed the CLI. That changes once aws login or the Console asks for an IAM user sign in.

The IAM user screen asks for an account ID or alias, an IAM username, and a password, and mjfrigaard-cli doesn’t have a password yet.

The IAM user sign in screen asks for an account ID or alias, an IAM username, and a password

The IAM user sign in screen asks for an account ID or alias, an IAM username, and a password

When we log into the Console as root, we can see the IAM users dashboard shows this.

The IAM users dashboard: mjfrigaard-cli has no password age and Console access is Disabled

The IAM users dashboard: mjfrigaard-cli has no password age and Console access is Disabled

The Password age column for mjfrigaard-cli is empty (-) and Console access is Disabled, which means the user has never had a Console password. There’s nothing to reset, so we enable Console access instead. Sign in to the Console as root one last time and:

  1. Go to IAM > IAM users and click mjfrigaard-cli.

  2. Open the Security credentials tab.

  3. Under Console sign-in, click Enable console access.

    Enable console access on the Security credentials tab

    Enable console access on the Security credentials tab
  4. Choose Custom password and enter a strong password. Leave “User must create a new password at next sign-in” unchecked, because this is our own account.

    Choose Custom password in the Enable console access dialog

    Choose Custom password in the Enable console access dialog
  5. Click Enable console access. The confirmation shows the Console sign-in URL with the account ID or alias.

    The Console password confirmation shows the sign-in URL, user name, and a one-time view of the password

    The Console password confirmation shows the sign-in URL, user name, and a one-time view of the password

From here on, sign in as the IAM user with the account ID or alias, mjfrigaard-cli, and the new password. Save root for the few tasks that require it: billing, changing the root email or password, closing the account, or restoring access if every IAM admin is locked out.

Console Home signed in as mjfrigaard-cli: the account menu shows the IAM user, and widgets outside its permissions show Access denied

Console Home signed in as mjfrigaard-cli: the account menu shows the IAM user, and widgets outside its permissions show Access denied

Rotating access keys

The access key we created for mjfrigaard-cli is a long-term credential. It never expires on its own, so anyone who finds it can use it until we delete it. The IAM users dashboard shows the key’s age in the Active key age column, and it flags keys older than 90 days with a warning icon.

Rotating means replacing the key with a new one on a schedule. An IAM user can hold two access keys at once, which lets us rotate without downtime. We create the new key, switch everything over, and only then retire the old one.

Checking the current keys

Start by listing the user’s keys and checking when each one was last used. These commands need IAM permissions. We attach IAMFullAccess to dev-deploy-group in Stand up an EC2 instance, and after that the dev-deploy profile can run them:

aws iam list-access-keys \
  --user-name mjfrigaard-cli \
  --profile dev-deploy
{
    "AccessKeyMetadata": [
        {
            "UserName": "mjfrigaard-cli",
            "AccessKeyId": "OLD_ACCESS_KEY_ID",
            "Status": "Active",
            "CreateDate": "2026-07-04T07:01:27+00:00"
        }
    ]
}

mjfrigaard-cli has one active key. Copy its AccessKeyId; the next command and step 4 of the rotation use it as OLD_ACCESS_KEY_ID.

aws iam get-access-key-last-used \
  --access-key-id OLD_ACCESS_KEY_ID \
  --profile dev-deploy
{
    "UserName": "mjfrigaard-cli",
    "AccessKeyLastUsed": {
        "LastUsedDate": "2026-11-19T06:47:00+00:00",
        "ServiceName": "ec2",
        "Region": "us-east-1"
    }
}

list-access-keys returns each key’s ID, status, and creation date. get-access-key-last-used returns the last date, service, and region the key was used. A key that hasn’t been used in months can be deleted without rotating. Ours was used recently for EC2, so it’s still in use and we rotate it instead.

Rotating the key

The rotation takes five steps, and the old key keeps working until the fourth:

  1. Create a second key. Copy the secret from the output; AWS won’t show it again.

    aws iam create-access-key \
      --user-name mjfrigaard-cli \
      --profile dev-deploy

    When we create a key in the Console and choose Command Line Interface (CLI), AWS recommends aws login (short-term credentials from our Console sign-in) or AWS CloudShell (a terminal in the browser) instead. We keep the long-term key because every lab uses the dev-deploy profile, so check “I understand the above recommendation and want to proceed to create an access key” and continue.

    The Access key best practices & alternatives page recommends aws login and AWS CloudShell

    The Access key best practices & alternatives page recommends aws login and AWS CloudShell
  2. Put the new key everywhere the old one lives. For this book that’s only the local dev-deploy profile. GitHub Actions doesn’t use this key (GitHub Actions and S3 uses a role instead), so there’s nothing to update there.

    aws configure --profile dev-deploy
  3. Confirm the new key works:

    aws sts get-caller-identity --profile dev-deploy
    {
        "UserId": "USER_ID",
        "Account": "ACCOUNT_ID",
        "Arn": "arn:aws:iam::ACCOUNT_ID:user/mjfrigaard-cli"
    }

    The Arn ends in user/mjfrigaard-cli, so the profile now signs in with the new key.

  4. Deactivate the old key. A deactivated key can be turned back on if something still depended on it.

    aws iam update-access-key \
      --user-name mjfrigaard-cli \
      --access-key-id OLD_ACCESS_KEY_ID \
      --status Inactive \
      --profile dev-deploy
  5. After a few days with nothing broken, delete it:

    aws iam delete-access-key \
      --user-name mjfrigaard-cli \
      --access-key-id OLD_ACCESS_KEY_ID \
      --profile dev-deploy

    List the keys again to confirm only the new one is left:

    aws iam list-access-keys \
      --user-name mjfrigaard-cli \
      --profile dev-deploy
    {
        "AccessKeyMetadata": [
            {
                "UserName": "mjfrigaard-cli",
                "AccessKeyId": "NEW_ACCESS_KEY_ID",
                "Status": "Active",
                "CreateDate": "2026-11-20T05:59:13+00:00"
            }
        ]
    }

Rotation best practices

The five steps above work for any long-term key, but I’ve found the order matters more than the commands. Each step leaves a way back until the old key is gone. The diagram below shows the full cycle, including what to do when something breaks:

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace'}}}%%

graph TD
    Start(["<strong>Key reaches 90 days</strong>"])
    Create("Create a<br>second key")
    Update("Update every place<br>the old key lives")
    Works{"New key<br>works?"}
    Deact("Deactivate<br>the old key")
    Broken{"Anything break<br>in a few days?"}
    React("Reactivate the old key<br>and find what used it")
    Delete("Delete<br>the old key")
    Done(["<strong>One active key</strong>"])

    Start -->|"i. create"| Create
    Create -->|"ii. switch"| Update
    Update -->|"iii. verify"| Works
    Works -->|"no"| Update
    Works -->|"yes, iv. deactivate"| Deact
    Deact --> Broken
    Broken -->|"yes"| React
    React --> Update
    Broken -->|"no, v. delete"| Delete
    Delete --> Done

    style Start fill:#E8A33D,stroke:#000000,stroke-width:1px,color:#ffffff
    style Create fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    style Update fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    style Works fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style Deact fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    style Broken fill:#1B2A41,stroke:#000000,stroke-width:1px,color:#ffffff
    style React fill:#D2562B,stroke:#000000,stroke-width:1px,color:#ffffff
    style Delete fill:#2A6F77,stroke:#000000,stroke-width:1px,color:#ffffff
    style Done fill:#5B8C5A,stroke:#000000,stroke-width:1px,color:#ffffff

Access key rotation cycle

These habits keep each rotation safe and on schedule:

  • Rotate every 90 days: this matches the IAM dashboard warning and most security guidance. A calendar reminder works better than waiting for the warning icon.
  • Keep one active key: the second slot is for rotation, not for a spare. Two active keys means two secrets to protect.
  • List where the key lives before you start: for this book it’s only ~/.aws/credentials. A key you forgot to update is the most common reason a rotation breaks something.
  • Verify before you deactivate: aws sts get-caller-identity should return the mjfrigaard-cli ARN with the new key. If it doesn’t, the old key still works, so nothing is lost.
  • Deactivate before you delete: a deactivated key can be turned back on, but a deleted key is gone for good.

Cleaning up the old key

Before deleting the old key, check that nothing used it after we deactivated it. An inactive key can’t sign requests, so its last used date should stay the same:

aws iam get-access-key-last-used \
  --access-key-id OLD_ACCESS_KEY_ID \
  --profile dev-deploy

Copies of the old key can also outlive it in notes, scripts, or shell history. Search for the old key ID and remove any copies you find (-I skips binary files, and -l prints only the file names):

grep -rIl "OLD_ACCESS_KEY_ID" ~ 2>/dev/null

When a key leaks

A leaked key changes the order. Deactivate it right away, even if something still depends on it, then create the new key and update each place it’s used. A few minutes of downtime is better than leaving a working key in someone else’s hands.

Key management practices

Rotation limits how long a leaked key stays useful, but a few habits keep keys from leaking at all:

  • Never commit keys: they belong in ~/.aws/credentials or a secrets store (like GitHub secrets), never in code, .env files under version control, or chat messages.
  • Delete unused keys: get-access-key-last-used shows which ones are safe to remove.
  • Prefer short-lived credentials where you can: aws login and IAM Identity Center issue credentials that expire on their own. GitHub Actions can assume an IAM role through OpenID Connect (OIDC) instead of storing keys at all (we set this up in GitHub Actions and S3).

Recap

  1. We created the dev-deploy-group IAM group, attached the AmazonEC2FullAccess and AmazonS3FullAccess policies, and added the mjfrigaard-cli user to it. The user has no permissions of its own; it inherits them from the group.

  2. We created an access key for mjfrigaard-cli with the Command Line Interface (CLI) use case. The Access Key ID and Secret Access Key authenticate requests, so they stay private (ARNs, by contrast, are identifiers and safe to share).

  3. We installed the AWS CLI with the official installer, confirmed it with aws --version, and stored the keys in a dev-deploy profile with aws configure. Running aws sts get-caller-identity --profile dev-deploy returned the mjfrigaard-cli ARN, which confirms the credentials work.

  4. We enabled Console access for mjfrigaard-cli, so everyday sign ins use the IAM user instead of root.

  5. We rotate the access key every 90 days by creating a second key, switching the dev-deploy profile to it, then deactivating and deleting the old one.

In the next section, we’re going to cover launching an EC2 instance.


  1. Read more about AWS IAM users↩︎

  2. Read more about AWS IAM user groups↩︎

  3. Read more about AWS IAM policies↩︎

  4. This is conceptually similar to a Linux ACL entry, but scoped to AWS API actions instead of filesystem operations.↩︎

  5. Read more about AWS ARNs in the official documentation.↩︎