liveBook · Manning

IAM policy

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

An IAM policy is a document that defines permissions by allowing or denying actions on resources for AWS identities or principals.

An IAM policy defines permissions for requests to AWS services. IAM checks the caller’s identity and whether an action is allowed; users and roles have no permissions by default. An identity policy grants permissions when attached to a user, group, or role. section 5.3.2

A policy is a JSON document containing one or more statements:

  • Effect says Allow or Deny; Action names the permitted or denied API actions. If both effects apply to an action, Deny wins. section 5.3.3
  • Resource identifies what the statement applies to. * is broad; an Amazon Resource Name (ARN) can identify a specific resource. Conditions can narrow a permission further. section 5.3.3 section 5.3.5
  • Identity policies attach to identities. Resource policies attach to supported resources, such as S3 buckets, and use Principal to identify who may act. section 5.3.3
{
   "Version": "2012-10-17",
   "Statement": [{
     "Effect": "Allow",
     "Action": "ec2:*",
     "Resource": "*"
   }, {
     "Effect": "Deny",                      #1
     "Action": "ec2:TerminateInstances",    #2
     "Resource": "*"
   }]
}

This policy allows EC2 actions but explicitly denies terminating instances. The Deny still applies despite the broader Allow. section 5.3.3

For a person, attach an identity policy directly or use a group to manage shared permissions. Reusable managed policies may be maintained by AWS or by you. For an AWS workload, use a role rather than storing a user’s access keys on an EC2 instance. An EC2 role can, for example, allow StopInstances only when an instance has a specified tag; a Lambda role can allow CreateTags for its task. Grant only the actions and resources needed. section 5.3.3 section 5.3.4 section 5.3.5 section 6.3.4

IAM policies control RDS and ElastiCache configuration actions, not access inside a database or cache. Database and cache engines handle their own internal access; security groups control network access to cache nodes. section 10.4.1 section 11.3.1

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Works through JSON statements, deny precedence, resource ARNs, policy types, and conditional permissions, without detailing a full policy-evaluation procedure.
Examples
Uses EC2 termination and self-stopping policies, a Lambda tagging policy, and RDS policies that deny destructive actions.
What it assumes
Introduces IAM identities and authorization from their basic roles before showing policies; assumes familiarity with AWS API requests and JSON examples.
What you can do after
Apply it via JSON or CloudFormation to grant task-specific AWS permissions and explicitly deny unwanted actions.
How it connects
Connects IAM users, groups, roles, resource policies, ARNs, CloudFormation, Lambda, RDS, and ElastiCache.

Also explained in

Compare how 3 books explain IAM policy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.