IAM policy example: give each user an S3 home folder, with a least privilege rewrite
Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.
Allows each IAM user to list and use only the prefix named after the user inside one bucket, using the aws:username policy variable. The variable resolves per caller, so one policy serves every user. The rewrite removes the wildcard on the object actions and keeps the prefix condition.
Open the workbench ยท All examples
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListOwnPrefix",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
"Condition": {
"StringLike": {
"s3:prefix": [
"home/${aws:username}/*"
]
}
}
},
{
"Sid": "OwnObjects",
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*"
}
]
}
What it allows
- The first statement lists only keys that start with home/ and the caller's user name.
- The second statement allows every S3 action on objects under that same prefix.
What it allows
Allow 1 action (s3:ListBucket) on arn:aws:s3:::amzn-s3-demo-bucket when s3:prefix StringLike home/${aws:username}/*.
Action or pattern Actions Access levels s3:ListBucket1 List 1 Allow 180 actions (s3:*) on arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*.
Action or pattern Actions Access levels s3:*180 List 18, Read 66, Write 57, Permissions management 27, Tagging 12
Checks
No flags from the six checks.
The object statement uses s3:*, which covers 180 actions, including ACL and tagging changes on the home folder.
Least privilege rewrite
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListOwnPrefix",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
"Condition": {
"StringLike": {
"s3:prefix": [
"home/${aws:username}/*"
]
}
}
},
{
"Sid": "OwnObjects",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*"
}
]
}
The rewrite replaces s3:* with three object actions. Users keep read, write and delete in their own folder but cannot change object ACLs or tags.
What it allows
Allow 1 action (s3:ListBucket) on arn:aws:s3:::amzn-s3-demo-bucket when s3:prefix StringLike home/${aws:username}/*.
Action or pattern Actions Access levels s3:ListBucket1 List 1 Allow 3 actions (s3:GetObject, s3:PutObject, s3:DeleteObject) on arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*.
Action or pattern Actions Access levels s3:GetObject1 Read 1 s3:PutObject1 Write 1 s3:DeleteObject1 Write 1
Checks
No flags from the six checks.
Related pages
Sources
- Amazon S3 User Guide: bucket policy and user policy walkthrough, read 16 Nov 2026
- Amazon S3 User Guide: identity-based policy examples, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.