class BucketPolicy (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.S3.BucketPolicy |
Java | software.amazon.awscdk.services.s3.BucketPolicy |
Python | aws_cdk.aws_s3.BucketPolicy |
TypeScript (source) | @aws-cdk/aws-s3 » BucketPolicy |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
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 * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
declare const bucket: s3.Bucket;
const bucketPolicy = new s3.BucketPolicy(this, 'MyBucketPolicy', {
bucket: bucket,
// the properties below are optional
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
Initializer
new BucketPolicy(scope: Construct, id: string, props: BucketPolicyProps)
Parameters
- scope
Construct
- id
string
- props
Bucket
Policy Props
Construct Props
Name | Type | Description |
---|---|---|
bucket | IBucket | The Amazon S3 bucket that the policy applies to. |
removal | Removal | Policy to apply when the policy is removed from this stack. |
bucket
Type:
IBucket
The Amazon S3 bucket that the policy applies to.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.DESTROY.)
Policy to apply when the policy is removed from this stack.
Properties
Name | Type | Description |
---|---|---|
document | Policy | A policy document containing permissions to add to the specified bucket. |
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
document
Type:
Policy
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.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
Methods
Name | Description |
---|---|
apply | Sets the removal policy for the BucketPolicy. |
to | Returns a string representation of this construct. |
RemovalPolicy(removalPolicy)
applypublic applyRemovalPolicy(removalPolicy: RemovalPolicy): void
Parameters
- removalPolicy
Removal
— the RemovalPolicy to set.Policy
Sets the removal policy for the BucketPolicy.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.