Skip to the content

Lesson 252 of 296

AWS IAM

What you will learn

  • What AWS is and how accounts and regions are organised
  • IAM users, groups, roles and policies
  • Reading and writing a policy
  • Roles for applications instead of keys
  • Least privilege and other IAM best practices
On this page

AWS in one paragraph

Amazon Web Services (AWS) rents computing resources over the internet: servers, databases, storage, queues and hundreds of managed services, paid for by use. It is organised into regions (geographic areas, such as eu-west-2 London and eu-west-1 Ireland), each with several availability zones (AZs): separate data centres with independent power and networking. Spreading an app across two or three AZs protects it from one data centre failing. UK companies often choose eu-west-2 for data location and latency.

The shared responsibility model: AWS secures the cloud itself (buildings, hardware, the virtualisation layer); you secure what you put in it: your IAM permissions, network rules, data encryption choices, operating system patches on EC2, and application code.

IAM: Identity and Access Management

IAM controls who can do what on which resources. Every AWS API call is checked against IAM.

ConceptMeaning
Root userThe account owner's email login. All powers. Lock it away: enable MFA, never use it day to day, never create access keys for it
IAM userA long-term identity for a person or (in the past) an application, with a password and/or access keys
GroupA set of users sharing policies
RoleAn identity without permanent credentials that is assumed temporarily by a service, an application, a user, or another account. Gives temporary credentials
PolicyA JSON document listing allowed or denied actions

For people in organisations, modern practice is IAM Identity Center (single sign-on with temporary credentials) rather than individual IAM users with access keys.

Policies

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadWriteUploadsForThisApp",
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Resource": "arn:aws:s3:::jobprep-uploads/tenants/*"
    },
    {
      "Sid": "SendToEmailQueue",
      "Effect": "Allow",
      "Action": "sqs:SendMessage",
      "Resource": "arn:aws:sqs:eu-west-2:123456789012:email-jobs"
    }
  ]
}
FieldMeaning
VersionThe policy language version; always "2012-10-17" (a fixed value, not a date to update)
EffectAllow or Deny
ActionAPI operations, service:Operation, wildcards allowed (s3:Get*)
ResourceWhich resources, by ARN (Amazon Resource Name)
ConditionOptional extra rules: source IP, MFA present, tags, time, VPC

How decisions work: everything is denied by default; an explicit Allow grants access; an explicit Deny anywhere always wins over any Allow.

Policy kinds: identity-based (attached to users, groups, roles), resource-based (attached to a resource, such as an S3 bucket policy or SQS queue policy, naming who may access it), plus organisation-wide guardrails (Service Control Policies) and permission boundaries.

Roles for applications

Never put access keys inside application code, environment files on servers, or images. Give the compute a role:

Where the code runsHow it gets credentials
EC2An instance profile (a role attached to the instance)
LambdaThe function's execution role
ECS / FargateThe task role (separate from the task execution role used to pull images and read secrets)
GitHub ActionsOIDC trust to assume a role (Lesson 251)
Another AWS accountCross-account role assumption

The AWS SDK finds these temporary credentials automatically and refreshes them; your code just creates clients (new S3Client({ region: "eu-west-2" })).

A role has two parts: a trust policy (who may assume it, for example lambda.amazonaws.com) and permission policies (what it may do).

Best practices

  • Least privilege: grant only the actions and resources needed. Start narrow; add when something fails (CloudTrail and IAM Access Analyzer show what is actually used).
  • No long-lived access keys where roles or OIDC are possible. If keys must exist, rotate them.
  • MFA for all humans; root locked down.
  • Separate accounts for production, staging and development (AWS Organizations), so a mistake in dev cannot touch production.
  • CloudTrail records every API call: who did what and when, for auditing and incident investigation.
  • Watch for over-broad policies: "Action": "*" and "Resource": "*" together means administrator access.

How to say it in an interview

"IAM decides which identities can perform which actions on which resources. Everything is denied by default, an Allow grants access, and an explicit Deny always wins. Policies are JSON with Effect, Action, Resource and optional Conditions, attached to identities or to resources like bucket policies. Applications never hold access keys: EC2 uses instance profiles, Lambda an execution role, ECS a task role, and CI uses OIDC, all giving temporary credentials the SDK picks up automatically. I follow least privilege, MFA, a locked-down root user, separate accounts per environment and CloudTrail for auditing."

Key words

WordMeaning
Region / availability zoneA geographic area / a separate data centre within it
Shared responsibilityAWS secures the cloud; you secure what you build in it
IAM user / roleLong-term identity / temporarily assumed identity
PolicyJSON permissions document
ARNAmazon Resource Name: a unique resource identifier
Trust policyWho may assume a role
Least privilegeOnly the permissions actually needed
CloudTrailA log of all AWS API calls

Now prove it

This lesson is complete when you pass the quiz and all three practice levels.