Skip to main content

🧑‍💻 03. IAM Policies

IAM Policies define permissions for users, groups, and roles in AWS. They determine what actions are allowed or denied on which resources, under what conditions. Policies are written in JSON format and are the backbone of AWS security management.


🧱 IAM Policy Structure

An IAM Policy document is made up of one or more statements, each describing a specific permission rule.

🧩 Structure Components

FieldDescriptionExample
VersionDefines the policy language version (always use "2012-10-17")"Version": "2012-10-17"
IdOptional unique identifier for the policy"Id": "S3ReadOnlyAccessPolicy"
StatementContains one or more permission rules

Each Statement block includes:

FieldPurposeExample
SidOptional statement ID"Sid": "AllowS3List"
EffectEither Allow or Deny"Effect": "Allow"
PrincipalEntity (user, role, account) to which the policy applies"Principal": {"AWS": "arn:aws:iam::123456789012:user/Alice"}
ActionAWS actions permitted or denied"Action": "s3:ListBucket"
ResourceThe AWS resources affected"Resource": "arn:aws:s3:::my-bucket"
ConditionOptional filters when policy is in effect"Condition": {"IpAddress": {"aws:SourceIp": "203.0.113.0/24"}}

📜 Example IAM Policy JSON

{
"Version": "2012-10-17",
"Id": "S3ReadOnlyAccessPolicy",
"Statement": [
{
"Sid": "S3ListAccess",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:user/Alice" },
"Action": ["s3:ListBucket", "s3:GetObject"],
"Resource": [
"arn:aws:s3:::my-example-bucket",
"arn:aws:s3:::my-example-bucket/*"
]
}
]
}

🧩 IAM Policy Inheritance

In AWS IAM, permissions can be inherited through multiple levels:

EntityReceives Permissions FromExample
UserDirectly attached policies and group membershipsAlice gets EC2 access via the Developers group
GroupPolicies attached to the groupDevelopers, Operations, Audit Team
RolePolicies attached to the roleUsed for EC2, Lambda, or cross-account access
Inline PolicyPolicy directly embedded within a user, group, or roleFred has a custom inline policy

✍️ Attaching Policies To User


✒️ Attaching Policies To Group


👷‍♂️ Creating Custom Policies


👷‍♂️ Attaching Custom Policies