☁️ AWS Hands-On Lab

From Console to CLI: Building a Secure AWS Identity with IAM

A self-contained, safe, and practical lab covering AWS Global Infrastructure, IAM, and the AWS CLI — designed for beginner to early-intermediate learners. Complete in ~120–150 minutes.

⏱ 120–150 min 🎯 Beginner → Intermediate 💻 Console + AWS CLI v2 🆓 Free Tier friendly

📘 0. Knowledge Summary (Generated First)

Since previous knowledge was not available, this concise summary establishes the foundation for the lab.

🌍 AWS Global Infrastructure

  • Regions: Geographically isolated areas (us-east-1).
  • Availability Zones: Discrete data centers with redundant power/networking.
  • Data Centers: Physical buildings housing servers and storage.
  • Edge Locations / PoPs: CDN endpoints for CloudFront & Route 53.
  • Local Zones: Region extensions in metro areas for low-latency workloads.
  • Region choice: Compliance, latency, service availability, pricing.

🔐 IAM & AWS CLI

  • IAM: Global service for access management.
  • Users, Groups, Policies: Identities and JSON permissions.
  • Default deny: Only explicit allows grant access.
  • MFA: Second authentication factor.
  • AWS CLI: aws <service> <operation>.
  • IAM Roles: Temporary credentials for services.
  • Best practices: Least privilege, MFA everywhere, rotate keys.

🧠 Key Concepts at a Glance

Each concept includes an icon, tag, and a real-world comparison.

🌎 Infrastructure

AWS Region

A geographic cluster of data centers isolated from other Regions.

Like: A country where your data "lives" — chosen for compliance and latency.

🏢 Infrastructure

Availability Zone

A physically separate data center within a Region, linked by low-latency fiber.

Like: A different building in the same city — if one burns, the other survives.

📡 CDN

Edge Location

Smaller sites closer to users for caching and routing.

Like: A local coffee shop chain that stocks the popular items nearby.

🏙️ Latency

Local Zone

A mini-Region extension inside a big city for <10ms workloads.

Like: A neighborhood branch that keeps essentials close to home.

👤 Identity

IAM User

A person or application with long-term credentials.

Like: An employee ID badge that you carry permanently.

👥 Identity

IAM Group

A collection of users sharing policies.

Like: A department — give the department a key, and everyone benefits.

📜 Policy

IAM Policy

A JSON document defining allowed or denied actions.

Like: A contract listing exactly what you can and cannot do.

🛡️ Security

MFA

A second factor (app, key, or SMS) on top of a password.

Like: A door needing both a key and a fingerprint.

🎭 Access

IAM Role

Temporary credentials assumed by trusted entities.

Like: A visitor badge you hand back at the end of the day.

⌨️ Tooling

AWS CLI

Command-line access to AWS services.

Like: A universal remote for every AWS service.

🧰 Tooling

AWS SDK

Language libraries (Python, Java, JS) to call AWS APIs.

Like: A toolbox made for your programming language.

📊 Audit

Credential Report

CSV listing users, MFA status, and key rotation.

Like: A payroll report for credentials.

🔎 Audit

Access Advisor

Shows which services a user actually accessed.

Like: A log of every door a badge ever opened.

🚫 Security

Default Deny

IAM denies everything unless explicitly allowed.

Like: A club where nobody enters without being on the guest list.

🏷️ Policy

Least Privilege

Grant only the minimum permissions required.

Like: Giving a cleaner a key to the office — not to the safe.

🎯 1. Lab Title & Inferred Learning Objectives

Lab Title: From Console to CLI — Building a Secure AWS Identity with IAM and Exploring AWS Global Infrastructure

Inferred Learning Objectives

Because no objectives were provided, they were inferred from the topic scope:

  1. 1 Identify the components of AWS Global Infrastructure (Regions, AZs, Edge Locations, Local Zones) and explain when to use each.
  2. 2 Construct a least-privilege IAM setup with Users, Groups, Policies, and MFA.
  3. 3 Configure the AWS CLI with named profiles and verify identity using aws sts get-caller-identity.
  4. 4 Demonstrate using IAM Roles for AWS services instead of embedding long-term credentials.
  5. 5 Evaluate IAM security posture using Credential Reports and Access Advisor.

📋 2. Assumptions

Item Assumption
AudienceBeginner to early-intermediate
Duration120–150 minutes
ToolsAWS Console, AWS CLI v2, virtual MFA app
EnvironmentAWS Cloud (Free Tier only)
PrerequisitesAWS account with root access, laptop, terminal
CostFree Tier only; cleanup mandatory
Regionus-east-1
SafetyNo production data, no public buckets, no long-lived root keys
If you already have IAM users, adapt Step B4 by using different names (e.g., foglamp-dev-<yourname>).

⚙️ 3. Prerequisites & Environment Setup

3.1 Software to Install

Tool Purpose Install
AWS CLI v2Terminal access to AWSSee commands below
jqParse JSON outputapt install jq
Virtual MFA AppScan QR for MFAGoogle Authenticator / Authy

Install AWS CLI v2 (Linux):

# Download and install AWS CLI v2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version

Install AWS CLI v2 (macOS):

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
aws --version

Expected output:

aws-cli/2.x.x Python/3.x.x Darwin/... or Linux/...

3.2 AWS Account Preparation

  • Log in to the AWS Console as root.
  • Enable MFA on root.
  • Set a budget alert at $1 to catch unexpected charges.
  • Open the IAM Console and confirm the dashboard loads.

🏢 4. Real-World Scenario

FogLamp Analytics is a 5-person startup building a weather-analytics dashboard. The CTO has asked you to:

  • 👤 Onboard a junior developer (dev-junior) with read-only S3 access.
  • 🔐 Ensure the developer uses MFA.
  • ⌨️ Give the developer CLI access for scripted uploads.
  • 🎭 Prepare an IAM Role for an EC2 instance that will later write logs to S3.
  • 🛡️ Prove compliance with least privilege and best practices.

🚀 5. Step-by-Step Lab Instructions

Follow the parts in order. Each has checkpoints to confirm progress.

🌍

Part A — Explore AWS Global Infrastructure (Console)

Step A1 — Identify Regions and AZs

  1. Log in to the AWS Console.
  2. Click the Region selector (top-right) and browse the list.
  3. Note 3 Regions and codes (e.g., us-east-1, eu-west-1, ap-southeast-1).
  4. Navigate to EC2 Console → EC2 Dashboard.
  5. Under Service Health, observe AZ names like us-east-1a.
✅ Checkpoint A1: You can name 3 Regions, their codes, and at least 2 AZs.

Step A2 — Observe Edge Locations and Local Zones

  1. Open CloudFront Console → Distributions (do not create one).
  2. Visit the global infrastructure map: aws.amazon.com/about-aws/global-infrastructure.
  3. Identify 3 Edge Locations near you and 1 Local Zone (if available).
✅ Checkpoint A2: Explain Edge Location vs Availability Zone in one sentence.
🔐

Part B — IAM Setup (Console)

Step B1 — Create an IAM Group

  1. IAM Console → User groupsCreate group.
  2. Group name: foglamp-developers.
  3. Skip policies → Create group.

Step B2 — Create a Least-Privilege Policy

IAM → PoliciesCreate policyJSON tab. Paste:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListAllBuckets",
      "Effect": "Allow",
      "Action": ["s3:ListAllMyBuckets"],
      "Resource": "*"
    },
    {
      "Sid": "ReadOnlyOnFogLampBucket",
      "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetObject", "s3:GetObjectVersion"],
      "Resource": [
        "arn:aws:s3:::foglamp-lab-<yourname>",
        "arn:aws:s3:::foglamp-lab-<yourname>/*"
      ]
    }
  ]
}

Replace <yourname>. Name: FogLampS3ReadOnly. Create.

✅ Checkpoint B2: Policy exists with 0 attachments.

Step B3 — Attach Policy to Group

  1. IAM → User groupsfoglamp-developersAdd permissionsAttach policies.
  2. Search FogLampS3ReadOnly → select → Add permissions.

Step B4 — Create an IAM User

  1. IAM → UsersCreate user.
  2. Username: dev-junior.
  3. Enable console access → custom password → uncheck "must reset".
  4. Add to group foglamp-developers → Create.
  5. Download the .csv with credentials and store securely.
✅ Checkpoint B4: User listed as member of the group.

Step B5 — Enforce an IAM Password Policy

IAM → Account settingsPassword policy → Edit:

  • Minimum length: 12
  • Require uppercase, lowercase, number, symbol: Yes
  • Password expiration: 90 days
  • Prevent reuse: 5

Step B6 — Enable MFA for dev-junior

  1. IAM → Users → dev-juniorSecurity credentialsAssign MFA device.
  2. Name: dev-junior-phone.
  3. Choose Authenticator app → scan QR.
  4. Enter two consecutive MFA codes → Add MFA.
✅ Checkpoint B6: MFA device listed as active.
⌨️

Part C — AWS CLI Configuration

Step C1 — Create Access Keys for dev-junior

  1. IAM → Users → dev-juniorSecurity credentialsCreate access key.
  2. Use case: Command Line Interface (CLI) → acknowledge → Create.
  3. Download CSV. Never share or commit these keys.

Step C2 — Configure a Named CLI Profile

aws configure --profile foglamp-dev

Provide:

AWS Access Key ID [None]: <paste access key>
AWS Secret Access Key [None]: <paste secret key>
Default region name [None]: us-east-1
Default output format [None]: json

Verify:

ls ~/.aws
cat ~/.aws/config

Step C3 — Verify Identity

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

Expected output:

{
  "UserId": "AIDA...",
  "Account": "123456789012",
  "Arn": "arn:aws:iam::123456789012:user/dev-junior"
}
✅ Checkpoint C3: ARN ends with user/dev-junior.

Step C4 — List Regions via CLI

aws ec2 describe-regions --profile foglamp-dev \
  --query "Regions[].RegionName" --output table

Step C5 — List Availability Zones

aws ec2 describe-availability-zones --profile foglamp-dev \
  --region us-east-1 \
  --query "AvailabilityZones[].ZoneName" --output table

Expected output: us-east-1a, us-east-1b, etc.

🪣

Part D — S3 Interaction with the CLI

Step D1 — Create a Bucket (as admin)

Console: S3 → Create bucket → Name foglamp-lab-<yourname> → Region us-east-1 → Block all public access → Create.

Step D2 — Upload a Test Object (as admin)

echo "FogLamp test file" > test.txt
aws s3 cp test.txt s3://foglamp-lab-<yourname>/test.txt --profile default

Step D3 — Read the Object as dev-junior

aws s3 ls s3://foglamp-lab-<yourname>/ --profile foglamp-dev
aws s3 cp s3://foglamp-lab-<yourname>/test.txt downloaded.txt --profile foglamp-dev
cat downloaded.txt

Expected: FogLamp test file.

Step D4 — Verify Least Privilege (Denied Action)

aws s3 cp test.txt s3://foglamp-lab-<yourname>/test2.txt --profile foglamp-dev

Expected output:

upload failed: ./test.txt to s3://foglamp-lab-<yourname>/test2.txt
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
✅ Checkpoint D4: AccessDenied confirms least privilege works.
🎭

Part E — IAM Roles for Services

Step E1 — Create a Role for EC2

  1. IAM → RolesCreate role.
  2. Trusted entity: AWS serviceEC2.
  3. Attach policy: AmazonS3ReadOnlyAccess.
  4. Role name: FogLampEC2S3ReadOnly → Create.

Step E2 — Inspect the Trust Policy

aws iam get-role --role-name FogLampEC2S3ReadOnly \
  --query "Role.AssumeRolePolicyDocument" --output json
Why this matters: EC2 assumes this role and receives temporary credentials — no access keys stored on the instance.
📊

Part F — IAM Security Tools

Step F1 — Generate a Credential Report

aws iam generate-credential-report
sleep 5
aws iam get-credential-report --query "Content" --output text | base64 -d > creds.csv
column -s, -t creds.csv | head -20

Expected: table showing users, MFA status, key rotation, last login.

Step F2 — Check Access Advisor

Console: IAM → Users → dev-juniorAccess Advisor tab → observe recently accessed services.

✅ Checkpoint F2: Identify at least one service accessed (S3, STS).

6. Expected Outputs / Checkpoints Summary

Step Checkpoint
A1Name 3 Regions, codes, 2 AZs
A2Explain Edge Location vs AZ
B2Policy FogLampS3ReadOnly created
B4User dev-junior created, in group
B6MFA active for dev-junior
C3get-caller-identity returns user/dev-junior
C5AZs listed for us-east-1
D4Upload denied (AccessDenied)
E1Role FogLampEC2S3ReadOnly created
F1creds.csv shows MFA status

🔍 7. Validation Steps

  1. 1. Identity Validation

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

    ARN must end with user/dev-junior.

  2. 2. Policy Validation

    aws iam list-attached-group-policies --group-name foglamp-developers

    Must list FogLampS3ReadOnly.

  3. 3. MFA Validation

    aws iam list-mfa-devices --user-name dev-junior

    Must return one MFA device.

  4. 4. Role Validation

    aws iam list-roles --query "Roles[?RoleName=='FogLampEC2S3ReadOnly'].RoleName"
  5. 5. Least Privilege Validation

    Step D4 must produce AccessDenied.

🛠️ 8. Troubleshooting Table

Symptom Cause Fix
Unable to locate credentialsCLI profile not configuredRe-run aws configure --profile foglamp-dev
AccessDenied on S3 readBucket ARN mismatchUpdate policy Resource ARN
MFA codes rejectedPhone time driftEnable auto time sync
InvalidClientTokenIdKey deleted/wrongRecreate access key
NoSuchBucketBucket in different RegionMatch bucket Region
Credential report emptyNot generated yetWait 10–30s, retry
Console login failsPassword policy mismatchReset password (12+, symbol)
aws: command not foundCLI not on PATHReinstall, open new terminal

🧹 9. Cleanup Steps

⚠️ Perform in this order to avoid orphaned resources.

1. Delete test object and bucket

aws s3 rm s3://foglamp-lab-<yourname>/test.txt
aws s3 rb s3://foglamp-lab-<yourname>

2. Delete access keys

aws iam list-access-keys --user-name dev-junior
aws iam delete-access-key --user-name dev-junior --access-key-id <AKIA...>

3. Remove MFA device

aws iam deactivate-mfa-device --user-name dev-junior --serial-number <arn-of-mfa>
aws iam delete-virtual-mfa-device --serial-number <arn-of-mfa>

4. Remove user from group and delete

aws iam remove-user-from-group --user-name dev-junior --group-name foglamp-developers
aws iam delete-user --user-name dev-junior

5. Detach and delete policy

aws iam detach-group-policy --group-name foglamp-developers \
  --policy-arn arn:aws:iam::<account-id>:policy/FogLampS3ReadOnly
aws iam delete-policy --policy-arn arn:aws:iam::<account-id>:policy/FogLampS3ReadOnly

6. Delete group

aws iam delete-group --group-name foglamp-developers

7. Delete role

aws iam detach-role-policy --role-name FogLampEC2S3ReadOnly \
  --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
aws iam delete-role --role-name FogLampEC2S3ReadOnly

8. Remove local files

rm -f ~/.aws/credentials ~/.aws/config
rm -f creds.csv test.txt downloaded.txt

9. Verify in Console

IAM Users, Groups, Policies, Roles lists should be empty (except AWS-managed).

📝 10. Assessment Questions with Answer Key

Q1. Difference between an AWS Region and an Availability Zone?

A Region is a geographic area with multiple isolated AZs. An AZ is one or more discrete data centers with redundant power and networking within a Region.

Q2. Why does IAM use "default deny"?

To enforce least privilege — nothing is allowed unless explicitly permitted in a policy.

Q3. Difference between an IAM User and an IAM Role?

A User has long-term credentials. A Role provides temporary credentials assumed by trusted entities (users, services, federated identities).

Q4. Which CLI command verifies your current AWS identity?

aws sts get-caller-identity

Q5. What does MFA add to authentication?

A second factor beyond the password, reducing risk if the password is compromised.

Q6. Why attach policies to groups instead of individual users?

Simplifies management, ensures consistency, and reduces orphaned permissions.

Q7. Purpose of Principal in a role trust policy?

It defines who or what is allowed to assume the role (e.g., ec2.amazonaws.com).

Q8. Which IAM tool shows services a user actually accessed?

IAM Access Advisor.

Q9. Which Region-selection factor relates to legal requirements?

Compliance and data residency.

Q10. What is an Edge Location used for?

Caching content and reducing latency for CloudFront, Route 53, and Global Accelerator.

Q11. Name two IAM best practices.

Enable MFA on root and privileged users; grant least privilege.

Q12. What does aws configure --profile <name> do?

Creates a named profile storing credentials and region in ~/.aws/credentials and ~/.aws/config.

Q13. Why did Step D4 intentionally fail?

To prove the least-privilege policy denies unauthorized actions.

Q14. What is an AWS Local Zone?

An extension of a Region placed in a metro area to run latency-sensitive workloads closer to end users.

Q15. Safest way to give EC2 access to S3?

Attach an IAM Role to the instance so it receives temporary credentials — never embed access keys.

🏆 11. Challenge / Extension Tasks

  1. 1 Multi-Region Exploration: List all AZs across 3 Regions and export to CSV.
  2. 2 Policy Boundary: Create an IAM Permissions Boundary limiting dev-junior to S3 and STS.
  3. 3 Password Rotation Script: Bash script rotating the console password every 30 days.
  4. 4 CloudTrail Verification: Locate the denied PutObject call from Step D4.
  5. 5 Access Analyzer: Enable and identify external resource shares.
  6. 6 Local Zone Exploration: Find a Local Zone in your country and describe a workload that benefits.
  7. 7 Boto3 Bonus: Rewrite Step D3 in Python using boto3 and profile foglamp-dev.
  8. 8 Cost Guardrail: Create a budget alert at $1 and simulate a notification.