AWS Amazon S3 Bucket Policy

This page shows how to write Terraform and CloudFormation for Amazon S3 Bucket Policy and write them securely.

code-icon

Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.

get-started-button

Terraform Example (aws_s3_bucket_policy)

Attaches a policy to an S3 bucket resource.

Parameters

Example Usage (from GitHub)

github-iconkanchwala-yusuf/aws-terraform
resource "aws_s3_bucket_policy" "allowActionsFromAllPrincipals" {
  bucket = "test"

  policy = <<POLICY
{
  "Version": "2012-10-17",
github-iconstelligent/config-lint
resource "aws_s3_bucket_policy" "policy_statement_allow_action_without_wildcard" {
  bucket = aws_s3_bucket.test_bucket.id

  policy = <<EOF
{
  "Version": "2012-10-17",
github-iconstelligent/config-lint
resource "aws_s3_bucket_policy" "policy_statement_allow_principal_without_wildcard" {
  bucket = aws_s3_bucket.test_bucket.id

  policy = <<EOF
{
  "Version": "2012-10-17",

CloudFormation Example (AWS::S3::BucketPolicy)

Applies an Amazon S3 bucket policy to an Amazon S3 bucket. If you are using an identity other than the root user of the AWS account that owns the bucket, the calling identity must have the PutBucketPolicy permissions on the specified bucket and belong to the bucket owner's account in order to use this operation.

If you don't have PutBucketPolicy permissions, Amazon S3 returns a 403 Access Denied error. If you have the correct permissions, but you're not using an identity that belongs to the bucket owner's account, Amazon S3 returns a 405 Method Not Allowed error.

Important As a security precaution, the root user of the AWS account that owns a bucket can always use this operation, even if the policy explicitly denies the root user the ability to perform this action. For more information, see Bucket policy examples.

The following operations are related to PutBucketPolicy:+ CreateBucket + DeleteBucket

Parameters

Frequently asked questions

What is AWS Amazon S3 Bucket Policy?

AWS Amazon S3 Bucket Policy is a resource for Amazon S3 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon S3 Bucket Policy?

For Terraform, the kanchwala-yusuf/aws-terraform, stelligent/config-lint and stelligent/config-lint source code examples are useful. See the Terraform Example section for further details.