# IAM policy example: limit S3 access to a VPC endpoint, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Allows object reads and writes on one bucket only when the request arrives through one VPC endpoint, using the aws:SourceVpce condition key. Requests from the internet or other endpoints get no allow. The original uses an s3:* action, and the rewrite narrows it to three.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "FromEndpointOnly",
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket",
        "arn:aws:s3:::amzn-s3-demo-bucket/*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:SourceVpce": "vpce-1a2b3c4d"
        }
      }
    }
  ]
}
```

## What it allows

- Allows every S3 action on the bucket and its objects when the request comes through the VPC endpoint vpce-1a2b3c4d.

- Allows 180 actions (s3:*) on arn:aws:s3:::amzn-s3-demo-bucket, arn:aws:s3:::amzn-s3-demo-bucket/* when aws:SourceVpce StringEquals vpce-1a2b3c4d.

Checks:
- No flags.

The network condition is sound, yet s3:* covers 180 actions, including bucket policy changes.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListFromEndpoint",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
      "Condition": {
        "StringEquals": {
          "aws:SourceVpce": "vpce-1a2b3c4d"
        }
      }
    },
    {
      "Sid": "ObjectsFromEndpoint",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*",
      "Condition": {
        "StringEquals": {
          "aws:SourceVpce": "vpce-1a2b3c4d"
        }
      }
    }
  ]
}
```

The rewrite keeps the endpoint condition on each statement and lists three actions. Bucket policy and delete actions are removed.

- Allows 1 action (s3:ListBucket) on arn:aws:s3:::amzn-s3-demo-bucket when aws:SourceVpce StringEquals vpce-1a2b3c4d.
- Allows 2 actions (s3:GetObject, s3:PutObject) on arn:aws:s3:::amzn-s3-demo-bucket/* when aws:SourceVpce StringEquals vpce-1a2b3c4d.

Checks:
- No flags.

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

## Related pages

- [IAM policy example: read EC2 inventory](/examples/ec2-describe-read-only/)
- [IAM policy example: start and stop tagged EC2 instances](/examples/ec2-start-stop-own-tagged-instances/)
- [IAM policy example: limit EC2 actions to one Region](/examples/ec2-actions-in-one-region/)
- [All of them](/examples/)

## Sources

- Amazon S3 User Guide: security best practices: https://docs.aws.amazon.com/AmazonS3/latest/userguide/security-best-practices.html (read 16 Nov 2026)
- Amazon S3 User Guide: bucket policy examples: https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.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-access-only-from-vpc-endpoint/

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