DevTools Logo

AWS IAM & S3 Policies Cheat Sheet

Quick reference for AWS IAM and S3 policies: JSON policy structure, actions, conditions, resource ARNs, and least-privilege patterns.

Security Tools
aws
iam
s3

AWS IAM policies are JSON documents that grant or deny actions on resources. Every request is checked against the union of the caller's policies; an explicit Deny always wins over Allow.

Policy Structure

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadOwnBucket",
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "arn:aws:s3:::my-bucket/*",
      "Condition": {
        "StringEquals": { "aws:PrincipalAccount": "${aws:username}" }
      }
    }
  ]
}
Table
FieldPurposeExample
VersionPolicy language version"2012-10-17"
Statement[]One or more statements
EffectAllow or Deny"Deny"
ActionAPI operations"s3:GetObject", "ec2:*"
ResourceARN(s) the actions apply to"arn:aws:s3:::bucket/*"
ConditionContext-based restrictions"IpAddress", "StringEquals"
SidOptional statement identifier"DenyDeleteLogs"

Common Action Patterns

json
{ "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::my-bucket" }
{ "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-bucket/*" }
Table
ServiceCommon actions
S3s3:ListBucket, s3:GetObject, s3:PutObject, s3:DeleteObject
EC2ec2:DescribeInstances, ec2:RunInstances, ec2:StopInstances
IAMiam:CreateUser, iam:AttachUserPolicy
Lambdalambda:InvokeFunction, lambda:CreateFunction
DynamoDBdynamodb:GetItem, dynamodb:Query, dynamodb:PutItem
CloudWatchlogs:CreateLogGroup, logs:PutLogEvents

S3 Bucket Policy

A bucket policy attaches to the bucket itself and can grant access to other accounts or public principals:

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadForWebsite",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-bucket/public/*"
    }
  ]
}
Table
Key difference from IAM policyExplanation
PrincipalWho the policy applies to (IAM policies omit it)
Action / ResourceSame grammar
Bucket vs object ARN:::bucket (list) vs :::bucket/* (objects)

Least-Privilege Conditions

json
{
  "Effect": "Deny",
  "Action": "s3:*",
  "Resource": "arn:aws:s3:::my-bucket/*",
  "Condition": {
    "Bool": { "aws:SecureTransport": "false" }
  }
}
Table
Condition operatorUse
StringEquals / StringLikeExact or wildcard string match
IpAddress / NotIpAddressSource IP restrictions
BoolBoolean context keys (aws:SecureTransport)
NumericLessThanEqualsNumeric context keys (s3:MaxKeys)
ArnEquals / ArnLikeARN comparisons

Common Pitfalls

[!WARNING] An explicit Deny statement overrides all Allows. Use deny-first for global protections like "no S3 delete outside the org".

[!TIP] Attach policies to roles/groups, not users; grant the narrowest Action list possible, and always restrict the Resource ARN — never "*" unless truly needed.

References