S3 Bucket Policy Generator for AWS
A bucket policy is the resource-based policy attached to one bucket: it decides which principals, from this account or others, may act on the bucket and its objects. For background, see the AWS S3 bucket policy documentation.
This generator builds one bucket-policy statement at a time: choose who it applies to (the principal), the S3 actions, the bucket or object ARNs, and optional conditions. The result is a resource-based policy you attach to the bucket, with Terraform, CloudFormation, CDK and Pulumi versions. To grant an IAM role access to S3 from the role's side instead (an identity policy), use the Inline Policy Generator.
Bucket-level actions (s3:ListBucket) use arn:aws:s3:::bucket; object actions (s3:GetObject) use arn:aws:s3:::bucket/*.
To generate, add at least one action, at least one bucket or object ARN, a principal.
Generate a policy, then export it as Terraform, OpenTofu, CloudFormation, AWS CDK, or Pulumi.
Check an existing policy
Configure your policy settings and click "Generate Policy" to see the result here, or check the structure of an existing policy using one of the options below.
Before you apply a bucket policy
A bucket has one policy
Applying a policy replaces the existing one. Read the current policy first (aws s3api get-bucket-policy), merge your new statement into it, and keep the result in version control.
Name a role, not an account
A principal such as arn:aws:iam::111122223333:role/ReportReader limits access to one role. An account root delegates the decision to that account's administrators.
Keep Block Public Access on
New buckets block public bucket policies by default. For websites, serve a private bucket through CloudFront with Origin Access Control instead of making the bucket public.
Validate, then test
The built-in check covers structure. Before applying, run IAM Access Analyzer's policy validation, then test an allowed and a denied request. Bucket policy best practices
Common bucket policy patterns
Reviewed, explained versions of the patterns most teams need. Each opens in this generator.
- Require HTTPS and an organization perimeterDeny plain-HTTP requests and callers outside your organization.
- CloudFront Origin Access ControlServe a private bucket through one distribution.
- Cross-account access through a roleLet another account read through a role you control.
- Keep Block Public Access on across accountsAn SCP baseline that also protects CloudTrail, GuardDuty and Config.
Sharing a bucket with another AWS account? The cross-account S3 access guide compares granting an external role in the bucket policy with role assumption, including KMS and verification steps.
What is an S3 bucket policy?
An S3 bucket policy is a JSON document attached to an Amazon S3 bucket that allows or denies actions on that bucket and its objects, for specific principals, under optional conditions. It is a resource-based policy: every statement names a Principal, and every resource must be the bucket or objects in it.
Within one AWS account, an Allow in either the bucket policy or the caller's IAM policy is enough, unless something explicitly denies the request. For a principal in another account, both the bucket policy and that principal's own IAM policies must allow it. An explicit Deny in any of them always wins.
Bucket policies are where guardrails belong too: denying requests that do not use TLS, or that come from outside your organisation, protects the data even if someone later grants too much elsewhere.
Frequently Asked Questions
What does this S3 bucket policy generator produce?
A bucket policy statement with a principal, S3 actions, bucket or object ARNs and optional conditions, as JSON and as Terraform, OpenTofu, CloudFormation, AWS CDK or Pulumi code that attaches it to an existing bucket.
What is the difference between a bucket policy and an IAM policy?
A bucket policy is attached to the bucket and names who may access it (the Principal). An IAM policy is attached to a user, group or role and has no Principal. In the same account either one can grant access; across accounts both must allow the request.
How do I grant another AWS account access to my bucket?
Name the specific IAM role from the other account as the principal (not the whole account), allow only the actions it needs on the bucket or a prefix, and have that account grant its role the same S3 permissions. The cross-account S3 guide walks through both this and the role-assumption alternative.
Can I build a policy with several statements?
The generator builds one statement at a time. Generate each statement and merge them into one policy document (a bucket has a single policy), or paste a complete policy into the validator on the right to check it. A pasted policy the form can't hold exactly is shown unchanged, never partially loaded.
Is it free, and does my policy leave the browser?
It is free and requires no signup. Policies are built and checked in your browser and are not sent to our servers.