Skip to main content

Overview

The S3Bucket construct provides secure object storage with SSL enforcement, auto-cleanup, and optional versioning. Configure a single class for all use cases: private storage, website hosting, and public read access.

Resource Class

Basic Usage

Standard Private Bucket

Website Hosting Bucket

Public Read Bucket

Default Behaviour

Configuration Options

Core Properties

All standard CDK BucketProps are also supported.

WebsiteHostingConfig

Use Cases

Private Application Storage

The default configuration creates a private bucket with SSL enforcement.

Static Website Hosting

Set websiteHosting to enable S3 website hosting. This automatically enables public read access and disables block public access settings.

Public Asset Delivery

Set publicReadAccess: true for publicly readable buckets. This disables block public access settings.
Public buckets expose all contents to the internet. Never store sensitive data in a public bucket. Consider CloudFront for access control.

Versioned Bucket with Backup Tier

When backupVaultTier is set to “resilient” or “enterprise”, versioning is automatically enabled with a 30-day noncurrent version expiration lifecycle rule.

Advanced Configuration

Encryption

Lifecycle Rules

Event Notifications

Access Control

Bucket Policies

IAM Permissions

CORS Configuration

Monitoring

Access Logging

Complete Example

Best Practices

  1. Enable versioning for data protection when needed
  2. Use encryption for sensitive data
  3. Configure lifecycle rules to reduce costs
  4. Enable access logging for security audits
  5. Use least privilege IAM policies
  6. Use websiteHosting instead of manual website configuration
  7. Use publicReadAccess instead of manual policy changes

Next Steps

ECR Repository

Store container images alongside object storage

Lambda Function

Process objects on upload with event notifications

IAM Role

Grant least-privilege access to bucket objects

Storage Factory

Create buckets with the StorageFactory pattern