Skip to content
v2.274.0

BucketProps Struct ​

Example ​

ts
const accessLogsBucket = new s3.Bucket(this, 'AccessLogsBucket', {
  objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,
});

accessLogsBucket.addToResourcePolicy(
  new iam.PolicyStatement({
    actions: ['s3:*'],
    resources: [accessLogsBucket.bucketArn, accessLogsBucket.arnForObjects('*')],
    principals: [new iam.AnyPrincipal()],
  })
)

const bucket = new s3.Bucket(this, 'MyBucket', {
  serverAccessLogsBucket: accessLogsBucket,
  serverAccessLogsPrefix: 'logs',
});

Properties ​

abacStatusbooleanabac_statusboolabacStatusBooleanAbacStatusboolAbacStatus*bool= The ABAC status is not set#
Enables Amazon S3 to evaluate the ABAC policy in the request.

Set to true to enable ABAC, false to explicitly disable it.

accessControlBucketAccessControlaccess_controlBucketAccessControlaccessControlBucketAccessControlAccessControlBucketAccessControlAccessControlBucketAccessControl= BucketAccessControl.PRIVATE#
Specifies a canned ACL that grants predefined permissions to the bucket.
autoDeleteObjectsbooleanauto_delete_objectsboolautoDeleteObjectsBooleanAutoDeleteObjectsboolAutoDeleteObjects*bool= false#
Whether all objects should be automatically deleted when the bucket is removed from the stack or when the stack is deleted.
notes

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.

blockedEncryptionTypesBlockedEncryptionType[]blocked_encryption_typestyping.List[BlockedEncryptionType]blockedEncryptionTypesList<BlockedEncryptionType>BlockedEncryptionTypesBlockedEncryptionType[]BlockedEncryptionTypes*[]BlockedEncryptionType= Amazon S3 determines which encry…#
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

Default: Amazon S3 determines which encryption types to block.

blockPublicAccessBlockPublicAccessblock_public_accessBlockPublicAccessblockPublicAccessBlockPublicAccessBlockPublicAccessBlockPublicAccessBlockPublicAccessBlockPublicAccess= CloudFormation defaults will app…#
The block public access configuration of this bucket.
default

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

bucketKeyEnabledbooleanbucket_key_enabledboolbucketKeyEnabledBooleanBucketKeyEnabledboolBucketKeyEnabled*bool= false#
Whether Amazon S3 should use its own intermediary key to generate data keys.
notes

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.

bucketNamestringbucket_namestrbucketNameStringBucketNamestringBucketName*string= Assigned by CloudFormation (reco…#
Physical name of this bucket.

Cannot be used together with bucketNamePrefix or bucketNamespace.

default

Default: Assigned by CloudFormation (recommended).

bucketNamePrefixstringbucket_name_prefixstrbucketNamePrefixStringBucketNamePrefixstringBucketNamePrefix*string= No prefix.#
A prefix for the bucket name in the account-regional namespace.
notes

Requires bucketNamespace to be set to ACCOUNT_REGIONAL. Cannot be used together with bucketName.

CloudFormation appends -<accountId>-<region>-an to form the full name. For example, my-app becomes my-app-123456789012-us-east-1-an.

Must contain only lowercase letters, numbers, and hyphens. Must start and end with a lowercase letter or number.

bucketNamespaceBucketNamespacebucket_namespaceBucketNamespacebucketNamespaceBucketNamespaceBucketNamespaceBucketNamespaceBucketNamespaceBucketNamespace= Global namespace.#
The namespace for the bucket name.
notes

AWS recommends ACCOUNT_REGIONAL for improved security, as bucket names are scoped to your account and cannot be claimed by other accounts. When set to ACCOUNT_REGIONAL, bucketNamePrefix is required. When set to GLOBAL, it can be used standalone to explicitly specify the default namespace.

corsCorsRule[]corstyping.List[CorsRule]corsList<CorsRule>CorsCorsRule[]Cors*[]CorsRule= No CORS configuration.#
The CORS configuration of this bucket.
encryptionBucketEncryptionencryptionBucketEncryptionencryptionBucketEncryptionEncryptionBucketEncryptionEncryptionBucketEncryption= `KMS` if `encryptionKey` is spec…#
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

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

encryptionKeyIKeyencryption_keyIKeyencryptionKeyIKeyEncryptionKeyIKeyEncryptionKeyIKey= If `encryption` is set to `KMS` …#
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

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

enforceSSLbooleanenforce_sslboolenforceSSLBooleanEnforceSSLboolEnforceSSL*bool= false#
Enforces SSL for requests.

S3.5 of the AWS Foundational Security Best Practices Regarding S3.

eventBridgeEnabledbooleanevent_bridge_enabledbooleventBridgeEnabledBooleanEventBridgeEnabledboolEventBridgeEnabled*bool= false#
Whether this bucket should send notifications to Amazon EventBridge or not.
intelligentTieringConfigurationsIntelligentTieringConfiguration[]intelligent_tiering_configurationstyping.List[IntelligentTieringConfiguration]intelligentTieringConfigurationsList<IntelligentTieringConfiguration>IntelligentTieringConfigurationsIntelligentTieringConfiguration[]IntelligentTieringConfigurations*[]IntelligentTieringConfiguration= No Intelligent Tiering Configura…#
Intelligent Tiering Configurations.
default

Default: No Intelligent Tiering Configurations.

inventoriesInventory[]inventoriestyping.List[Inventory]inventoriesList<Inventory>InventoriesInventory[]Inventories*[]Inventory= No inventory configuration#
The inventory configuration of the bucket.
lifecycleRulesLifecycleRule[]lifecycle_rulestyping.List[LifecycleRule]lifecycleRulesList<LifecycleRule>LifecycleRulesLifecycleRule[]LifecycleRules*[]LifecycleRule= No lifecycle rules.#
Rules that define how Amazon S3 manages objects during their lifetime.
metricsBucketMetrics[]metricstyping.List[BucketMetrics]metricsList<BucketMetrics>MetricsBucketMetrics[]Metrics*[]BucketMetrics= No metrics configuration.#
The metrics configuration of this bucket.
minimumTLSVersionnumberminimum_tls_versionint | floatminimumTLSVersionNumberMinimumTLSVersiondoubleMinimumTLSVersion*float64= No minimum TLS version is enforc…#
Enforces minimum TLS version for requests.

Requires enforceSSL to be enabled.

default

Default: No minimum TLS version is enforced.

notificationsHandlerRoleIRolenotifications_handler_roleIRolenotificationsHandlerRoleIRoleNotificationsHandlerRoleIRoleNotificationsHandlerRoleIRole= a new role will be created.#
The role to be used by the notifications handler.
notificationsSkipDestinationValidationbooleannotifications_skip_destination_validationboolnotificationsSkipDestinationValidationBooleanNotificationsSkipDestinationValidationboolNotificationsSkipDestinationValidation*bool= false#
Skips notification validation of Amazon SQS, Amazon SNS, and Lambda destinations.
objectLockDefaultRetentionObjectLockRetentionobject_lock_default_retentionObjectLockRetentionobjectLockDefaultRetentionObjectLockRetentionObjectLockDefaultRetentionObjectLockRetentionObjectLockDefaultRetentionObjectLockRetention= no default retention period#
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.

objectLockEnabledbooleanobject_lock_enabledboolobjectLockEnabledBooleanObjectLockEnabledboolObjectLockEnabled*bool= false, unless objectLockDefaultR…#
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

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

objectOwnershipObjectOwnershipobject_ownershipObjectOwnershipobjectOwnershipObjectOwnershipObjectOwnershipObjectOwnershipObjectOwnershipObjectOwnership= No ObjectOwnership configuration…#
The objectOwnership of the bucket.
default

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.

publicReadAccessbooleanpublic_read_accessboolpublicReadAccessBooleanPublicReadAccessboolPublicReadAccess*bool= false#
Grants public read access to all objects in the bucket.

Similar to calling bucket.grantPublicAccess()

removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= The bucket will be orphaned.#
Policy to apply when the bucket is removed from this stack.
replicationRoleIRolereplication_roleIRolereplicationRoleIRoleReplicationRoleIRoleReplicationRoleIRole= a new role will be created.#
The role to be used by the replication.

When setting this property, you must also set replicationRules.

replicationRulesReplicationRule[]replication_rulestyping.List[ReplicationRule]replicationRulesList<ReplicationRule>ReplicationRulesReplicationRule[]ReplicationRules*[]ReplicationRule= No replication#
A container for one or more replication rules.
serverAccessLogsBucketIBucketserver_access_logs_bucketIBucketserverAccessLogsBucketIBucketServerAccessLogsBucketIBucketServerAccessLogsBucketIBucket= If "serverAccessLogsPrefix" unde…#
Destination bucket for the server access logs.
default

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

serverAccessLogsPrefixstringserver_access_logs_prefixstrserverAccessLogsPrefixStringServerAccessLogsPrefixstringServerAccessLogsPrefix*string= No log file prefix#
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.

targetObjectKeyFormatTargetObjectKeyFormattarget_object_key_formatTargetObjectKeyFormattargetObjectKeyFormatTargetObjectKeyFormatTargetObjectKeyFormatTargetObjectKeyFormatTargetObjectKeyFormatTargetObjectKeyFormat= the default key format is: [Dest…#
Optional key format for log objects.
default

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

transferAccelerationbooleantransfer_accelerationbooltransferAccelerationBooleanTransferAccelerationboolTransferAcceleration*bool= false#
Whether this bucket should have transfer acceleration turned on or not.
transitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSizetransition_default_minimum_object_sizeTransitionDefaultMinimumObjectSizetransitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSizeTransitionDefaultMinimumObjectSize= TransitionDefaultMinimumObjectSi…#
Indicates which default minimum object size behavior is applied to the lifecycle configuration.
notes · default

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.

versionedbooleanversionedboolversionedBooleanVersionedboolVersioned*bool= false (unless object lock is ena…#
Whether this bucket should have versioning turned on or not.
default

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

websiteErrorDocumentstringwebsite_error_documentstrwebsiteErrorDocumentStringWebsiteErrorDocumentstringWebsiteErrorDocument*string= No error document.#
The name of the error document (e.g. "404.html") for the website. `websiteIndexDocument` must also be set if this is set.
websiteIndexDocumentstringwebsite_index_documentstrwebsiteIndexDocumentStringWebsiteIndexDocumentstringWebsiteIndexDocument*string= No index document.#
The name of the index document (e.g. "index.html") for the website. Enables static website hosting for this bucket.
websiteRedirectRedirectTargetwebsite_redirectRedirectTargetwebsiteRedirectRedirectTargetWebsiteRedirectRedirectTargetWebsiteRedirectRedirectTarget= No redirection.#
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".

websiteRoutingRulesRoutingRule[]website_routing_rulestyping.List[RoutingRule]websiteRoutingRulesList<RoutingRule>WebsiteRoutingRulesRoutingRule[]WebsiteRoutingRules*[]RoutingRule= No redirection rules.#
Rules that define when a redirect is applied and the redirect behavior.