- Inline Policies: Policies that you create and manage within a single IAM role, user, or group.
- Managed Policies: Standalone policies that you can attach to multiple users, groups, and roles.
Example of creating an inline policy:
Here is an example of creating an inline policy directly attached to a role using the AWS CLI:
aws iam put-role-policy --role-name ExampleRole --policy-name ExamplePolicy --policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::example-bucket"
}
]
}'
Example of creating a managed policy:
Here is an example of creating a managed policy using the AWS CLI:
aws iam create-policy --policy-name ExampleManagedPolicy --policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::example-bucket"
}
]
}'