Options
All
  • Public
  • Public/Protected
  • All
Menu

A construct representing an AutoDeleteBucket.

This construct creates an S3 bucket that will be automatically emptied before the bucket itself is destroyed. This prevents Cloud Formation failing to destroy a stack when existing S3 resources remain.

Hierarchy

  • Bucket
    • AutoDeleteBucket

Implements

  • IConstruct
  • IConstruct
  • IResource
  • IBucket

Index

Constructors

constructor

  • new AutoDeleteBucket(scope: Construct, id: string, props?: BucketProps): AutoDeleteBucket

Properties

Protected autoCreatePolicy

autoCreatePolicy: boolean

Indicates if a bucket resource policy should automatically created upon the first call to addToResourcePolicy.

stability

stable

Readonly bucketArn

bucketArn: string

The ARN of the bucket.

stability

stable

Readonly bucketDomainName

bucketDomainName: string

The IPv4 DNS name of the specified bucket.

stability

stable

Readonly bucketDualStackDomainName

bucketDualStackDomainName: string

The IPv6 DNS name of the specified bucket.

stability

stable

Readonly bucketName

bucketName: string

The name of the bucket.

stability

stable

Readonly bucketRegionalDomainName

bucketRegionalDomainName: string

The regional domain name of the specified bucket.

stability

stable

Readonly bucketWebsiteDomainName

bucketWebsiteDomainName: string

The Domain name of the static website.

stability

stable

Readonly bucketWebsiteUrl

bucketWebsiteUrl: string

The URL of the static website.

stability

stable

Protected Optional disallowPublicAccess

disallowPublicAccess: undefined | false | true

Whether to disallow public access.

stability

stable

Optional Readonly encryptionKey

encryptionKey: kms.IKey

Optional KMS encryption key associated with this bucket.

stability

stable

Readonly env

env: ResourceEnvironment

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.

stability

stable

Optional Readonly isWebsite

isWebsite: undefined | false | true

If this bucket has been configured for static website hosting.

stability

stable

Readonly node

node: ConstructNode

The construct tree node associated with this construct.

stability

stable

Protected Readonly physicalName

physicalName: string

(experimental) Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.

This value will resolve to one of the following:

  • a concrete value (e.g. "my-awesome-bucket")
  • undefined, when a name should be generated by CloudFormation
  • a concrete name generated automatically during synthesis, in cross-environment scenarios.
experimental

Optional policy

policy: BucketPolicy

The resource policy associated with this bucket.

If autoCreatePolicy is true, a BucketPolicy will be created upon the first call to addToResourcePolicy(s).

stability

stable

Readonly stack

stack: Stack

The stack in which this resource is defined.

stability

stable

Methods

_enableCrossEnvironment

  • _enableCrossEnvironment(): void
  • Called when this resource is referenced across environments (account/region) to order to request that a physical name will be generated for this resource during synthesis, so the resource can be referenced through it's absolute name/arn.

    internal

    Returns void

addCorsRule

  • addCorsRule(rule: CorsRule): void
  • Adds a cross-origin access configuration for objects in an Amazon S3 bucket.

    stability

    stable

    Parameters

    • rule: CorsRule

      The CORS configuration rule to add.

    Returns void

addEventNotification

  • addEventNotification(event: EventType, dest: IBucketNotificationDestination, ...filters: NotificationKeyFilter[]): void
  • Adds a bucket notification event destination.

    see

    https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html

    stability

    stable

    example

    bucket.addEventNotification(EventType.OnObjectCreated, myLambda, 'home/myusername/*')

    Parameters

    • event: EventType

      The event to trigger the notification.

    • dest: IBucketNotificationDestination

      The notification destination (Lambda, SNS Topic or SQS Queue).

    • Rest ...filters: NotificationKeyFilter[]

      S3 object key filter rules to determine which objects trigger this event.

    Returns void

addInventory

  • addInventory(inventory: Inventory): void
  • Add an inventory configuration.

    stability

    stable

    Parameters

    • inventory: Inventory

      configuration to add.

    Returns void

addLifecycleRule

  • addLifecycleRule(rule: LifecycleRule): void
  • Add a lifecycle rule to the bucket.

    stability

    stable

    Parameters

    • rule: LifecycleRule

      The rule to add.

    Returns void

addMetric

  • addMetric(metric: BucketMetrics): void
  • Adds a metrics configuration for the CloudWatch request metrics from the bucket.

    stability

    stable

    Parameters

    • metric: BucketMetrics

      The metric configuration to add.

    Returns void

addObjectCreatedNotification

  • addObjectCreatedNotification(dest: IBucketNotificationDestination, ...filters: NotificationKeyFilter[]): void
  • Subscribes a destination to receive notifications when an object is created in the bucket.

    This is identical to calling onEvent(EventType.ObjectCreated).

    stability

    stable

    Parameters

    • dest: IBucketNotificationDestination

      The notification destination (see onEvent).

    • Rest ...filters: NotificationKeyFilter[]

      Filters (see onEvent).

    Returns void

addObjectRemovedNotification

  • addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: NotificationKeyFilter[]): void
  • Subscribes a destination to receive notifications when an object is removed from the bucket.

    This is identical to calling onEvent(EventType.ObjectRemoved).

    stability

    stable

    Parameters

    • dest: IBucketNotificationDestination

      The notification destination (see onEvent).

    • Rest ...filters: NotificationKeyFilter[]

      Filters (see onEvent).

    Returns void

addToResourcePolicy

  • addToResourcePolicy(permission: PolicyStatement): AddToResourcePolicyResult
  • Adds a statement to the resource policy for a principal (i.e. account/role/service) to perform actions on this bucket and/or it's contents. Use bucketArn and arnForObjects(keys) to obtain ARNs for this bucket or objects.

    stability

    stable

    Parameters

    • permission: PolicyStatement

    Returns AddToResourcePolicyResult

arnForObjects

  • arnForObjects(keyPattern: string): string
  • Returns an ARN that represents all objects within the bucket that match the key pattern specified.

    To represent all keys, specify "*".

    If you need to specify a keyPattern with multiple components, concatenate them into a single string, e.g.:

    arnForObjects(home/${team}/${user}/*)

    stability

    stable

    Parameters

    • keyPattern: string

    Returns string

Protected generatePhysicalName

  • generatePhysicalName(): string

Protected getResourceArnAttribute

  • getResourceArnAttribute(arnAttr: string, arnComponents: ArnComponents): string
  • (experimental) Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. bucket.bucketArn).

    Normally, this token will resolve to arnAttr, but if the resource is referenced across environments, arnComponents will be used to synthesize a concrete ARN with the resource's physical name. Make sure to reference this.physicalName in arnComponents.

    experimental

    Parameters

    • arnAttr: string

      The CFN attribute which resolves to the ARN of the resource.

    • arnComponents: ArnComponents

      The format of the ARN of this resource.

    Returns string

Protected getResourceNameAttribute

  • getResourceNameAttribute(nameAttr: string): string
  • (experimental) Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. bucket.bucketName).

    Normally, this token will resolve to nameAttr, but if the resource is referenced across environments, it will be resolved to this.physicalName, which will be a concrete name.

    experimental

    Parameters

    • nameAttr: string

      The CFN attribute which resolves to the resource's name.

    Returns string

grantDelete

  • grantDelete(identity: IGrantable, objectsKeyPattern?: any): Grant
  • Grants s3:DeleteObject* permission to an IAM pricipal for objects in this bucket.

    stability

    stable

    Parameters

    • identity: IGrantable

      The principal.

    • Optional objectsKeyPattern: any

      Restrict the permission to a certain key pattern (default '*').

    Returns Grant

grantPublicAccess

  • grantPublicAccess(keyPrefix?: undefined | string, ...allowedActions: string[]): Grant
  • Allows unrestricted access to objects from this bucket.

    IMPORTANT: This permission allows anyone to perform actions on S3 objects in this bucket, which is useful for when you configure your bucket as a website and want everyone to be able to read objects in the bucket without needing to authenticate.

    Without arguments, this method will grant read ("s3:GetObject") access to all objects ("*") in the bucket.

    The method returns the iam.Grant object, which can then be modified as needed. For example, you can add a condition that will restrict access only to an IPv4 range like this:

     const grant = bucket.grantPublicAccess();
     grant.resourceStatement!.addCondition(‘IpAddress’, { “aws:SourceIp”: “54.240.143.0/24” });
    stability

    stable

    Parameters

    • Optional keyPrefix: undefined | string

      the prefix of S3 object keys (e.g. home/*). Default is "*".

    • Rest ...allowedActions: string[]

      the set of S3 actions to allow.

    Returns Grant

grantPut

  • grantPut(identity: IGrantable, objectsKeyPattern?: any): Grant
  • Grants s3:PutObject* and s3:Abort* permissions for this bucket to an IAM principal.

    If encryption is used, permission to use the key to encrypt the contents of written files will also be granted to the same principal.

    stability

    stable

    Parameters

    • identity: IGrantable

      The principal.

    • Optional objectsKeyPattern: any

      Restrict the permission to a certain key pattern (default '*').

    Returns Grant

grantPutAcl

  • grantPutAcl(identity: IGrantable, objectsKeyPattern?: undefined | string): Grant
  • Grant the given IAM identity permissions to modify the ACLs of objects in the given Bucket.

    If your application has the '@aws-cdk/aws-s3:grantWriteWithoutAcl' feature flag set, calling grantWrite or grantReadWrite no longer grants permissions to modify the ACLs of the objects; in this case, if you need to modify object ACLs, call this method explicitly.

    stability

    stable

    Parameters

    • identity: IGrantable
    • Optional objectsKeyPattern: undefined | string

    Returns Grant

grantRead

  • grantRead(identity: IGrantable, objectsKeyPattern?: any): Grant
  • Grant read permissions for this bucket and it's contents to an IAM principal (Role/Group/User).

    If encryption is used, permission to use the key to decrypt the contents of the bucket will also be granted to the same principal.

    stability

    stable

    Parameters

    • identity: IGrantable

      The principal.

    • Optional objectsKeyPattern: any

      Restrict the permission to a certain key pattern (default '*').

    Returns Grant

grantReadWrite

  • grantReadWrite(identity: IGrantable, objectsKeyPattern?: any): Grant
  • Grants read/write permissions for this bucket and it's contents to an IAM principal (Role/Group/User).

    If an encryption key is used, permission to use the key for encrypt/decrypt will also be granted.

    stability

    stable

    Parameters

    • identity: IGrantable

      The principal.

    • Optional objectsKeyPattern: any

      Restrict the permission to a certain key pattern (default '*').

    Returns Grant

grantWrite

  • grantWrite(identity: IGrantable, objectsKeyPattern?: any): Grant
  • Grant write permissions to this bucket to an IAM principal.

    If encryption is used, permission to use the key to encrypt the contents of written files will also be granted to the same principal.

    stability

    stable

    Parameters

    • identity: IGrantable

      The principal.

    • Optional objectsKeyPattern: any

      Restrict the permission to a certain key pattern (default '*').

    Returns Grant

onCloudTrailEvent

  • onCloudTrailEvent(id: string, options?: OnCloudTrailBucketEventOptions): Rule
  • Define a CloudWatch event that triggers when something happens to this repository.

    Requires that there exists at least one CloudTrail Trail in your account that captures the event. This method will not create the Trail.

    stability

    stable

    Parameters

    • id: string

      The id of the rule.

    • Optional options: OnCloudTrailBucketEventOptions

      Options for adding the rule.

    Returns Rule

onCloudTrailPutObject

  • onCloudTrailPutObject(id: string, options?: OnCloudTrailBucketEventOptions): Rule
  • Defines an AWS CloudWatch event that triggers when an object is uploaded to the specified paths (keys) in this bucket using the PutObject API call.

    Note that some tools like aws s3 cp will automatically use either PutObject or the multipart upload API depending on the file size, so using onCloudTrailWriteObject may be preferable.

    Requires that there exists at least one CloudTrail Trail in your account that captures the event. This method will not create the Trail.

    stability

    stable

    Parameters

    • id: string

      The id of the rule.

    • Optional options: OnCloudTrailBucketEventOptions

      Options for adding the rule.

    Returns Rule

onCloudTrailWriteObject

  • onCloudTrailWriteObject(id: string, options?: OnCloudTrailBucketEventOptions): Rule
  • Defines an AWS CloudWatch event that triggers when an object at the specified paths (keys) in this bucket are written to.

    This includes the events PutObject, CopyObject, and CompleteMultipartUpload.

    Note that some tools like aws s3 cp will automatically use either PutObject or the multipart upload API depending on the file size, so using this method may be preferable to onCloudTrailPutObject.

    Requires that there exists at least one CloudTrail Trail in your account that captures the event. This method will not create the Trail.

    stability

    stable

    Parameters

    • id: string

      The id of the rule.

    • Optional options: OnCloudTrailBucketEventOptions

      Options for adding the rule.

    Returns Rule

Protected onPrepare

  • onPrepare(): void
  • Perform final modifications before synthesis.

    This method can be implemented by derived constructs in order to perform final changes before synthesis. prepare() will be called after child constructs have been prepared.

    This is an advanced framework feature. Only use this if you understand the implications.

    stability

    stable

    Returns void

Protected onSynthesize

  • onSynthesize(session: ISynthesisSession): void
  • Allows this construct to emit artifacts into the cloud assembly during synthesis.

    This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

    stability

    stable

    Parameters

    • session: ISynthesisSession

      The synthesis session.

    Returns void

Protected onValidate

  • onValidate(): string[]
  • Validate the current construct.

    This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

    stability

    stable

    Returns string[]

    An array of validation error messages, or an empty array if the construct is valid.

Protected prepare

  • prepare(): void
  • Perform final modifications before synthesis.

    This method can be implemented by derived constructs in order to perform final changes before synthesis. prepare() will be called after child constructs have been prepared.

    This is an advanced framework feature. Only use this if you understand the implications.

    stability

    stable

    Returns void

s3UrlForObject

  • s3UrlForObject(key?: undefined | string): string
  • The S3 URL of an S3 object.

    For example:

    stability

    stable

    example

    s3://bucket/key

    Parameters

    • Optional key: undefined | string

      The S3 key of the object.

    Returns string

    an ObjectS3Url token

Protected synthesize

  • synthesize(session: ISynthesisSession): void
  • Allows this construct to emit artifacts into the cloud assembly during synthesis.

    This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

    stability

    stable

    Parameters

    • session: ISynthesisSession

      The synthesis session.

    Returns void

toString

  • toString(): string
  • Returns a string representation of this construct.

    stability

    stable

    Returns string

urlForObject

  • urlForObject(key?: undefined | string): string

Protected validate

  • validate(): string[]
  • Validate the current construct.

    This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

    stability

    stable

    Returns string[]

virtualHostedUrlForObject

  • virtualHostedUrlForObject(key?: undefined | string, options?: VirtualHostedStyleUrlOptions): string
  • The virtual hosted-style URL of an S3 object.

    Specify regional: false at the options for non-regional URL. For example:

    stability

    stable

    example

    https://china-bucket.s3.cn-north-1.amazonaws.com.cn/mykey

    Parameters

    • Optional key: undefined | string

      The S3 key of the object.

    • Optional options: VirtualHostedStyleUrlOptions

      Options for generating URL.

    Returns string

    an ObjectS3Url token

Static fromBucketArn

  • fromBucketArn(scope: Construct, id: string, bucketArn: string): IBucket
  • stability

    stable

    Parameters

    • scope: Construct
    • id: string
    • bucketArn: string

    Returns IBucket

Static fromBucketAttributes

  • fromBucketAttributes(scope: Construct, id: string, attrs: BucketAttributes): IBucket
  • Creates a Bucket construct that represents an external bucket.

    stability

    stable

    Parameters

    • scope: Construct

      The parent creating construct (usually this).

    • id: string

      The construct's name.

    • attrs: BucketAttributes

      A BucketAttributes object.

    Returns IBucket

Static fromBucketName

  • fromBucketName(scope: Construct, id: string, bucketName: string): IBucket
  • stability

    stable

    Parameters

    • scope: Construct
    • id: string
    • bucketName: string

    Returns IBucket

Static isConstruct

  • isConstruct(x: any): x is Construct
  • Return whether the given object is a Construct.

    stability

    stable

    Parameters

    • x: any

    Returns x is Construct

Legend

  • Constructor
  • Property
  • Method
  • Constructor
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Private property
  • Private method
  • Static property
  • Static method

Generated using TypeDoc