A policy is a short JSON document that lists what is allowed. Here is part of the one AWS calls AmazonS3ReadOnlyAccess:
json
{
"Effect": "Allow",
"Action": ["s3:Get*", "s3:List*"],
"Resource": "*"
}| Part | Means |
|---|---|
Effect | Allow lets it happen |
Action | what can be done: s3:Get* is every S3 action that starts with Get, such as reading an object |
Resource | on what: * is everything |
AWS has hundreds of ready-made AWS managed policies like this one. Each has an ARN: arn:aws:iam::aws:policy/<name>.
New command
aws iam attach-group-policy
Attaches a policy to a group. Every member gets what it allows.
Usageaws iam attach-group-policy --group-name group --policy-arn policy ARN
Example
aws iam attach-group-policy --group-name support --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
To test what a user can do, run a command as them, with --profile: aws s3 ls --profile kai. Without a policy, IAM says no:
text
An error occurred (AccessDenied) when calling the ListBuckets operation:
User: arn:aws:iam::123456789012:user/kai is not authorized to perform:
s3:ListAllMyBuckets because no identity-based policy allows the s3:ListAllMyBuckets action
↑ who ↑ what they tried ↑ why