AWS Cheatsheet
IAM
Use this AWS reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Core Concepts
| Concept | Description |
|---|---|
| User | Long-lived identity for a human or application. Gets access keys or console password. |
| Group | Collection of users. Attach policies to the group; all members inherit them. |
| Role | Temporary identity assumed by AWS services, EC2, Lambda, or cross-account callers. No long-lived keys. |
| Policy | JSON document listing allowed/denied actions on resources. |
| Permission Boundary | Max permissions an entity can ever have, regardless of attached policies. |
| SCP | Service Control Policy — org-level guardrail applied to accounts/OUs. |
Users
aws iam create-user --user-name alice aws iam list-users --query 'Users[*].[UserName,UserId,CreateDate]' --output table aws iam delete-user --user-name alice # Console password aws iam create-login-profile --user-name alice --password 'Temp!Pass1' --password-reset-required # Access keys aws iam create-access-key --user-name alice aws iam list-access-keys --user-name alice aws iam update-access-key --user-name alice --access-key-id AKIA... --status Inactive aws iam delete-access-key --user-name alice --access-key-id AKIA...
Groups
aws iam create-group --group-name developers
aws iam add-user-to-group --group-name developers --user-name alice
aws iam remove-user-from-group --group-name developers --user-name alice
aws iam list-groups-for-user --user-name alice
aws iam delete-group --group-name developersRoles
# Create role with trust policy (who can assume it)
aws iam create-role \
--role-name lambda-exec \
--assume-role-policy-document file://trust.jsonTrust policy — allow the Lambda service to assume (trust.json):
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "lambda.amazonaws.com" },
"Action": "sts:AssumeRole"
}]
}Trust policy — allow EC2 to assume:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}]
}Trust policy — cross-account assume:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::987654321098:root" },
"Action": "sts:AssumeRole",
"Condition": { "StringEquals": { "sts:ExternalId": "uniquetoken" } }
}]
}aws iam list-roles --query 'Roles[*].[RoleName,RoleId,CreateDate]' --output table aws iam get-role --role-name lambda-exec aws iam delete-role --role-name lambda-exec # must detach policies first
Policies
Managed Policies
# Attach AWS managed policy to user/role/group aws iam attach-user-policy --user-name alice --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess aws iam attach-role-policy --role-name my-role --policy-arn arn:aws:iam::aws:policy/AWSLambdaBasicExecutionRole aws iam attach-group-policy --group-name devs --policy-arn arn:aws:iam::aws:policy/PowerUserAccess # Detach aws iam detach-role-policy --role-name my-role --policy-arn arn:aws:iam::aws:policy/AWSLambdaBasicExecutionRole # List policies on a role aws iam list-attached-role-policies --role-name my-role # Search managed policies aws iam list-policies --scope AWS --query 'Policies[?contains(PolicyName,`S3`)].[PolicyName,Arn]' --output table
Customer Managed Policies
# Create aws iam create-policy \ --policy-name s3-read-my-bucket \ --policy-document file://policy.json # Update (new version) aws iam create-policy-version \ --policy-arn arn:aws:iam::123:policy/s3-read-my-bucket \ --policy-document file://policy-v2.json \ --set-as-default aws iam list-policy-versions --policy-arn arn:aws:iam::123:policy/s3-read-my-bucket aws iam delete-policy --policy-arn arn:aws:iam::123:policy/s3-read-my-bucket
Inline Policies
# Embed directly on a role (not reusable)
aws iam put-role-policy \
--role-name my-role \
--policy-name inline-s3 \
--policy-document file://policy.json
aws iam list-role-policies --role-name my-role
aws iam get-role-policy --role-name my-role --policy-name inline-s3
aws iam delete-role-policy --role-name my-role --policy-name inline-s3Policy JSON Structure
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3Read",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::my-bucket",
"arn:aws:s3:::my-bucket/*"
]
},
{
"Sid": "DenyDelete",
"Effect": "Deny",
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}Common Condition Keys
| Key | Example |
|---|---|
aws:SourceIp | "Condition":{"IpAddress":{"aws:SourceIp":"10.0.0.0/8"}} |
aws:MultiFactorAuthPresent | Require MFA: {"Bool":{"aws:MultiFactorAuthPresent":"true"}} |
aws:RequestedRegion | Restrict to a region |
aws:PrincipalTag | Attribute-based access control (ABAC) |
s3:prefix | Restrict S3 path |
sts:ExternalId | Cross-account role security |
STS — Temporary Credentials
# Assume a role aws sts assume-role \ --role-arn arn:aws:iam::123456789012:role/MyRole \ --role-session-name cli-session \ --duration-seconds 3600 # Check current identity aws sts get-caller-identity # Get session token (for MFA-required operations) aws sts get-session-token \ --serial-number arn:aws:iam::123:mfa/alice \ --token-code 123456 \ --duration-seconds 43200
Instance Profiles (EC2 → Role)
# Create instance profile and add role to it aws iam create-instance-profile --instance-profile-name web-profile aws iam add-role-to-instance-profile \ --instance-profile-name web-profile \ --role-name web-role # Attach to existing instance aws ec2 associate-iam-instance-profile \ --instance-id i-0abc123 \ --iam-instance-profile Name=web-profile
IAM Policy Simulator (CLI)
aws iam simulate-principal-policy \ --policy-source-arn arn:aws:iam::123:user/alice \ --action-names s3:GetObject s3:DeleteObject \ --resource-arns arn:aws:s3:::my-bucket/*
Audit & Security
# Generate credentials report (all users, key ages, MFA status) aws iam generate-credential-report aws iam get-credential-report --query 'Content' --output text | base64 -d # Access Advisor — which services were last accessed aws iam generate-service-last-accessed-details \ --arn arn:aws:iam::123:role/my-role # Use the job-id from above: aws iam get-service-last-accessed-details --job-id abc-123 # List all roles and their last activity aws iam get-account-summary
Common Managed Policy ARNs
| Policy | ARN |
|---|---|
| Admin | arn:aws:iam::aws:policy/AdministratorAccess |
| PowerUser | arn:aws:iam::aws:policy/PowerUserAccess |
| ReadOnly | arn:aws:iam::aws:policy/ReadOnlyAccess |
| Lambda basic exec | arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole |
| Lambda VPC | arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole |
| S3 full | arn:aws:iam::aws:policy/AmazonS3FullAccess |
| S3 read | arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess |
| EC2 full | arn:aws:iam::aws:policy/AmazonEC2FullAccess |
| ECS task exec | arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy |