Class BucketPolicy

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.s3.BucketPolicy
All Implemented Interfaces:
IResource, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-18T17:54:24.009Z") @Stability(Stable) public class BucketPolicy extends Resource
The bucket policy for an Amazon S3 bucket.

Policies define the operations that are allowed on this resource.

You almost never need to define this construct directly.

All AWS resources that support resource policies have a method called addToResourcePolicy(), which will automatically create a new resource policy if one doesn't exist yet, otherwise it will add to the existing policy.

Prefer to use addToResourcePolicy() instead.

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.*;
 import software.amazon.awscdk.services.s3.*;
 Bucket bucket;
 BucketPolicy bucketPolicy = BucketPolicy.Builder.create(this, "MyBucketPolicy")
         .bucket(bucket)
         // the properties below are optional
         .removalPolicy(RemovalPolicy.DESTROY)
         .build();
 
  • Constructor Details

    • BucketPolicy

      protected BucketPolicy(software.amazon.jsii.JsiiObjectRef objRef)
    • BucketPolicy

      protected BucketPolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • BucketPolicy

      @Stability(Stable) public BucketPolicy(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull BucketPolicyProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromCfnBucketPolicy

      @Stability(Stable) @NotNull public static BucketPolicy fromCfnBucketPolicy(@NotNull CfnBucketPolicy cfnBucketPolicy)
      Create a mutable BucketPolicy from a CfnBucketPolicy.

      Parameters:
      cfnBucketPolicy - This parameter is required.
    • applyRemovalPolicy

      @Stability(Stable) public void applyRemovalPolicy(@NotNull RemovalPolicy removalPolicy)
      Sets the removal policy for the BucketPolicy.

      Specified by:
      applyRemovalPolicy in interface IResource
      Overrides:
      applyRemovalPolicy in class Resource
      Parameters:
      removalPolicy - the RemovalPolicy to set. This parameter is required.
    • getBucket

      @Stability(Stable) @NotNull public IBucket getBucket()
      The Bucket this Policy applies to.
    • getDocument

      @Stability(Stable) @NotNull public PolicyDocument getDocument()
      A policy document containing permissions to add to the specified bucket.

      For more information, see Access Policy Language Overview in the Amazon Simple Storage Service Developer Guide.