# 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.

```json
{
  "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.

- Allows 1 action (s3:ListBucket) on arn:aws:s3:::amzn-s3-demo-bucket when s3:prefix StringLike home/${aws:username}/*.
- Allows 180 actions (s3:*) on arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*.

Checks:
- No flags.

The object statement uses s3:*, which covers 180 actions, including ACL and tagging changes on the home folder.

## Least privilege rewrite

```json
{
  "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.

- Allows 1 action (s3:ListBucket) on arn:aws:s3:::amzn-s3-demo-bucket when s3:prefix StringLike home/${aws:username}/*.
- Allows 3 actions (s3:GetObject, s3:PutObject, s3:DeleteObject) on arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every S3 action and its access level](/actions/s3/)

## Related pages

- [IAM policy example: deny S3 requests without TLS](/examples/s3-deny-non-tls-requests/)
- [IAM policy example: require KMS encryption on S3 uploads](/examples/s3-put-with-kms-encryption/)
- [IAM policy example: list S3 buckets in the console](/examples/s3-list-buckets-console/)
- [All of them](/examples/)

## Sources

- Amazon S3 User Guide: bucket policy and user policy walkthrough: https://docs.aws.amazon.com/AmazonS3/latest/userguide/walkthrough1.html (read 16 Nov 2026)
- Amazon S3 User Guide: identity-based policy examples: https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-policies-s3.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/s3-home-folder-by-username/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
