IAM policies are JSON documents that specify permissions. They determine what actions are allowed or denied for specific resources.
- Managed Policies: AWS or customer-created policies that can be attached to multiple entities.
- Inline Policies: Policies directly attached to a single user, group, or role.
-
Create an Inline Policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::example_bucket" } ] }
aws iam put-user-policy --user-name Alice --policy-name ListS3Policy --policy-document file://policy.json
-
Attach a Managed Policy:
aws iam attach-user-policy --user-name Alice --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
-
Create an Inline Policy:
- Sign in to the AWS Management Console.
- Open the IAM console at IAM Dashboard.
- In the navigation pane, click Users, then select the user.
- Click the Permissions tab and then Add inline policy.
- Enter the policy JSON or use the visual editor, then click Review policy.
- Enter a Policy name and click Create policy.
-
Attach a Managed Policy:
- In the IAM console, go to Users, then select the user.
- Click the Permissions tab and then Add permissions.
- Choose Attach policies directly.
- Search for and select the policy (e.g., AmazonS3ReadOnlyAccess).
- Click Next: Review, then Add permissions.
Next: AWS IAM Best Practices