AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

Bucket

An S3 bucket with associated policy objects. This bucket does not yet have all features that exposed by the underlying BucketResource.

Import

import { Bucket } from 'aws-cdk-lib/aws-s3';

Or use the module namespace:

import * as s3 from 'aws-cdk-lib/aws-s3';
// s3.Bucket

Properties

Configuration passed to the constructor as BucketProps.

abacStatusOptional
boolean

Enables Amazon S3 to evaluate the ABAC policy in the request. Set to true to enable ABAC, false to explicitly disable it.

Default: - The ABAC status is not set

accessControlOptional
BucketAccessControl

Specifies a canned ACL that grants predefined permissions to the bucket.

Default: BucketAccessControl.PRIVATE

autoDeleteObjectsOptional
boolean

Whether all objects should be automatically deleted when the bucket is removed from the stack or when the stack is deleted. Requires the `removalPolicy` to be set to `RemovalPolicy.DESTROY`. **Warning** if you have deployed a bucket with `autoDeleteObjects: true`, switching this to `false` in a CDK version *before* `1.126.0` will lead to all objects in the bucket being deleted. Be sure to update your bucket resources by deploying with CDK version `1.126.0` or later **before** switching this value to `false`. Setting `autoDeleteObjects` to true on a bucket will add `s3:PutBucketPolicy` to the bucket policy. This is because during bucket deletion, the custom resource provider needs to update the bucket policy by adding a deny policy for `s3:PutObject` to prevent race conditions with external bucket writers.

Default: false

blockedEncryptionTypesOptional
BlockedEncryptionType[]

Encryption types that should be blocked for this bucket. Use `NONE` to allow all encryption types. At least one `BlockedEncryptionType` must be given. If `NONE` is given, it must be the only `BlockedEncryptionType` in the list.

Default: - Amazon S3 determines which encryption types to block.

blockPublicAccessOptional
BlockPublicAccess

The block public access configuration of this bucket.

Default: - CloudFormation defaults will apply. New buckets and objects don't allow public access, but users can modify bucket policies or object permissions to allow public access

bucketKeyEnabledOptional
boolean

Whether Amazon S3 should use its own intermediary key to generate data keys. Only relevant when using KMS for encryption. - If not enabled, every object GET and PUT will cause an API call to KMS (with the attendant cost implications of that). - If enabled, S3 will use its own time-limited key instead. Only relevant, when Encryption is not set to `BucketEncryption.UNENCRYPTED`.

Default: - false

bucketNameOptional
string

Physical name of this bucket.

Default: - Assigned by CloudFormation (recommended).

corsOptional
CorsRule[]

The CORS configuration of this bucket.

Default: - No CORS configuration.

encryptionOptional
BucketEncryption

The kind of server-side encryption to apply to this bucket. If you choose KMS, you can specify a KMS key via `encryptionKey`. If encryption key is not specified, a key will automatically be created.

Default: - `KMS` if `encryptionKey` is specified, or `S3_MANAGED` otherwise.

encryptionKeyOptional
IKey

External KMS key to use for bucket encryption. The `encryption` property must be either not specified or set to `KMS` or `DSSE`. An error will be emitted if `encryption` is set to `UNENCRYPTED` or `S3_MANAGED`.

Default: - If `encryption` is set to `KMS` and this property is undefined, a new KMS key will be created and associated with this bucket.

enforceSSLOptional
boolean

Enforces SSL for requests. S3.5 of the AWS Foundational Security Best Practices Regarding S3.

Default: false

eventBridgeEnabledOptional
boolean

Whether this bucket should send notifications to Amazon EventBridge or not.

Default: false

intelligentTieringConfigurationsOptional
IntelligentTieringConfiguration[]

Intelligent Tiering Configurations.

Default: No Intelligent Tiering Configurations.

inventoriesOptional
Inventory[]

The inventory configuration of the bucket.

Default: - No inventory configuration

lifecycleRulesOptional
LifecycleRule[]

Rules that define how Amazon S3 manages objects during their lifetime.

Default: - No lifecycle rules.

metricsOptional
BucketMetrics[]

The metrics configuration of this bucket.

Default: - No metrics configuration.

minimumTLSVersionOptional
number

Enforces minimum TLS version for requests. Requires `enforceSSL` to be enabled.

Default: No minimum TLS version is enforced.

notificationsHandlerRoleOptional
IRole

The role to be used by the notifications handler.

Default: - a new role will be created.

notificationsSkipDestinationValidationOptional
boolean

Skips notification validation of Amazon SQS, Amazon SNS, and Lambda destinations.

Default: false

objectLockDefaultRetentionOptional
ObjectLockRetention

The default retention mode and rules for S3 Object Lock. Default retention can be configured after a bucket is created if the bucket already has object lock enabled. Enabling object lock for existing buckets is not supported.

Default: no default retention period

objectLockEnabledOptional
boolean

Enable object lock on the bucket. Enabling object lock for existing buckets is not supported. Object lock must be enabled when the bucket is created.

Default: false, unless objectLockDefaultRetention is set (then, true)

objectOwnershipOptional
ObjectOwnership

The objectOwnership of the bucket.

Default: - No ObjectOwnership configuration. By default, Amazon S3 sets Object Ownership to `Bucket owner enforced`. This means ACLs are disabled and the bucket owner will own every object.

publicReadAccessOptional
boolean

Grants public read access to all objects in the bucket. Similar to calling `bucket.grantPublicAccess()`

Default: false

removalPolicyOptional
RemovalPolicy

Policy to apply when the bucket is removed from this stack.

Default: - The bucket will be orphaned.

replicationRoleOptional
IRole

The role to be used by the replication. When setting this property, you must also set `replicationRules`.

Default: - a new role will be created.

replicationRulesOptional
ReplicationRule[]

A container for one or more replication rules.

Default: - No replication

serverAccessLogsBucketOptional
IBucket

Destination bucket for the server access logs.

Default: - If "serverAccessLogsPrefix" undefined - access logs disabled, otherwise - log to current bucket.

serverAccessLogsPrefixOptional
string

Optional log file prefix to use for the bucket's access logs. If defined without "serverAccessLogsBucket", enables access logs to current bucket with this prefix.

Default: - No log file prefix

targetObjectKeyFormatOptional
TargetObjectKeyFormat

Optional key format for log objects.

Default: - the default key format is: [DestinationPrefix][YYYY]-[MM]-[DD]-[hh]-[mm]-[ss]-[UniqueString]

transferAccelerationOptional
boolean

Whether this bucket should have transfer acceleration turned on or not.

Default: false

transitionDefaultMinimumObjectSizeOptional
TransitionDefaultMinimumObjectSize

Indicates which default minimum object size behavior is applied to the lifecycle configuration. To customize the minimum object size for any transition you can add a filter that specifies a custom `objectSizeGreaterThan` or `objectSizeLessThan` for `lifecycleRules` property. Custom filters always take precedence over the default transition behavior.

Default: - TransitionDefaultMinimumObjectSize.VARIES_BY_STORAGE_CLASS before September 2024, otherwise TransitionDefaultMinimumObjectSize.ALL_STORAGE_CLASSES_128_K.

versionedOptional
boolean

Whether this bucket should have versioning turned on or not.

Default: false (unless object lock is enabled, then true)

websiteErrorDocumentOptional
string

The name of the error document (e.g. "404.html") for the website. `websiteIndexDocument` must also be set if this is set.

Default: - No error document.

websiteIndexDocumentOptional
string

The name of the index document (e.g. "index.html") for the website. Enables static website hosting for this bucket.

Default: - No index document.

websiteRedirectOptional
RedirectTarget

Specifies the redirect behavior of all requests to a website endpoint of a bucket. If you specify this property, you can't specify "websiteIndexDocument", "websiteErrorDocument" nor , "websiteRoutingRules".

Default: - No redirection.

websiteRoutingRulesOptional
RoutingRule[]

Rules that define when a redirect is applied and the redirect behavior.

Default: - No redirection rules.

Get the Amazon S3 Cheat Sheet

Everything you need to know about Amazon S3 on one page. HD quality, print-friendly.

Download Free Infographic