Carina

Resource

awscc.s3.BucketPolicy

CloudFormation Type: 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. 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. When using the AWS::S3::BucketPolicy resource, you can create, update, and delete bucket policies for S3 buckets located in Regions that are different from the stack's Region. However, the CloudFormation stacks should be deployed in the US East (N. Virginia) or us-east-1 Region. This cross-region bucket policy modification functionality is supported for backward compatibility with existing workflows. If the DeletionPolicy attribute is not specified or set to Delete, the bucket policy will be removed when the stack is deleted. If set to Retain, the bucket policy will be preserved even after the stack is deleted. For example, a CloudFormation stack in us-east-1 can use the AWS::S3::BucketPolicy resource to manage the bucket policy for an S3 bucket in us-west-2. The retention or removal of the bucket policy during the stack deletion is determined by the DeletionPolicy attribute specified in the stack template. For more information, see Bucket policy examples. The following operations are related to PutBucketPolicy:

Example

let example_bucket = awscc.s3.Bucket {
  bucket_name = 'carina-example-policy-bucket'

  tags = {
    Environment = 'example'
  }
}

let bucket_reader = awscc.iam.Role {
  assume_role_policy_document = {
    version = aws.iam.PolicyDocument.Version.2012_10_17
    statement {
      effect = aws.iam.PolicyDocument.Statement.Effect.allow

      principal = {
        service = 'lambda.amazonaws.com'
      }

      action = 'sts:AssumeRole'
    }
  }
}

awscc.s3.BucketPolicy {
  bucket = example_bucket.bucket_name

  policy_document = {
    version = aws.iam.PolicyDocument.Version.2012_10_17
    statement {
      sid    = 'AllowReaderRoleToListBucket'
      effect = aws.iam.PolicyDocument.Statement.Effect.allow

      principal = {
        aws = bucket_reader.arn
      }

      action   = 's3:ListBucket'
      resource = example_bucket.arn
    }
  }
}

Argument Reference

bucket

The name of the Amazon S3 bucket to which the policy applies.

policy_document

A policy document containing permissions to add to the specified bucket. In IAM, you must provide policy documents in JSON format. However, in CloudFormation you can provide the policy in JSON or YAML format because CloudFormation converts YAML to JSON before submitting it to IAM. For more information, see the AWS::IAM::Policy PolicyDocument resource description in this guide and Access Policy Language Overview in the Amazon S3 User Guide.

AWS API narrowings

These fields are narrower than or equal to CFN. Input rules combine documented AWS domains, recorded live observations, and Carina canonical spellings for stable state comparison. A canonical DSL spelling does not claim AWS rejects other spellings. Attaching a type name adds no structural constraints. Field names below use CFN spelling.

CFN field Relation to CFN Evidence URL Verbatim quote / exact observation Checked / observed
/properties/PolicyDocument Subset: CFN ∩ reviewed input domain Source record <version_block> = "Version" : ("2008-10-17" | "2012-10-17")<effect_block> = "Effect" : ("Allow" | "Deny") 2026-11-07
/properties/PolicyDocument Subset: CFN ∩ reviewed input domain Source record The Statement element can contain a single statement or an array of individual statements. 2026-11-07
/properties/PolicyDocument Subset: CFN ∩ reviewed input domain Source record You can create conditions that compare strings, dates, numbers, and more using typical Boolean comparisons such as equals, greater than, and less than. 2026-11-07