Skip to main content

S3 Bucket

Manages S3 Buckets

Bucket Attributes#

Basic#

const s3Bucket = await provider.makeS3Bucket({
name: "yourgloballyuniquebucketnamehere",
properties: () => ({}),
});

Acceleration#

Enable or disable the bucket acceleration.

See the AccelerateConfiguration properties page

const s3Accelerated = await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere`,
properties: () => ({
AccelerateConfiguration: {
Status: "Enabled",
},
}),
});

CORS#

Set the CORS configuration for this bucket.

See the CORSConfiguration properties page for a full list of supported options.

await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere `,
properties: () => ({
CORSConfiguration: {
CORSRules: [
{
AllowedHeaders: ["Authorization"],
AllowedMethods: ["GET"],
AllowedOrigins: ["*"],
MaxAgeSeconds: 3000,
},
],
},
}),
});

Encryption#

Set the encryption configuration for this bucket.

See the ServerSideEncryptionConfiguration properties page for a full list of supported options.

const s3Encryption = await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere`,
properties: () => ({
ServerSideEncryptionConfiguration: {
Rules: [
{
ApplyServerSideEncryptionByDefault: {
SSEAlgorithm: "AES256",
},
},
],
},
}),
});

Lifecycle#

Enable or disable the bucket lifecycle.

See the LifecycleConfiguration properties page

const s3Lifecycle = await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere`,
properties: () => ({
LifecycleConfiguration: {
Rules: [
{
Expiration: {
Days: 3650,
},
Filter: {
Prefix: "documents/",
},
ID: "TestOnly",
Status: "Enabled",
Transitions: [
{
Days: 365,
StorageClass: "GLACIER",
},
],
},
],
},
}),
});

Logging#

Enable logging of one bucket to another.

See BucketLoggingStatus for as full list of properties.

The destination bucket must have its ACL set to log-delivery-write.

const bucketLogDestination = `yourgloballyuniquebucketnamehere-log-destination`;
await provider.makeS3Bucket({
name: bucketLogDestination,
properties: () => ({
ACL: "log-delivery-write",
}),
});
await provider.makeS3Bucket({
name: `${bucketName}-logged`,
properties: () => ({
BucketLoggingStatus: {
LoggingEnabled: {
TargetBucket: bucketLogDestination,
TargetPrefix: "MyBucketLogs/",
TargetGrants: [
{
Grantee: {
Type: "Group",
URI: "http://acs.amazonaws.com/groups/global/AllUsers",
},
Permission: "READ",
},
],
},
},
}),
});

Notification#

Set the notification configuration for this bucket.

See the NotificationConfiguration properties page for a full list of supported options.

Notification for SNS#

const bucketName = "yourgloballyuniquebucketnamehere";
const topicId = "123456789012";
await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere-notification-configuration`,
properties: () => ({
NotificationConfiguration: {
TopicConfigurations: [
{
Events: ["s3:ObjectCreated:*"],
TopicArn: `arn:aws:sns:us-west-2:${topicId}:s3-notification-topic`,
},
],
},
}),
});

Notification for Lambda Function#

const bucketName = "yourgloballyuniquebucketnamehere";
const lambdaFunctionArn = "123456789012";
await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere-notification-configuration`,
properties: () => ({
NotificationConfiguration: {
LambdaFunctionConfigurations: [
{
Events: ["s3:ObjectCreated"],
LambdaFunctionArn,
},
],
},
}),
});

Policy#

Set the policy configuration for this bucket.

See the Policy properties page for a full list of supported options.

const bucketName = "yourgloballyuniquebucketnamehere";
const s3pPolicy = await provider.makeS3Bucket({
name: bucketName,
properties: () => ({
Policy: JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Sid: "IPAllow",
Effect: "Deny",
Principal: "*",
Action: "s3:*",
Resource: `arn:aws:s3:::${bucketName}/*`,
Condition: {
IpAddress: { "aws:SourceIp": "8.8.8.8/32" },
},
},
],
}),
}),
});

Replication#

Set the replication configuration for this bucket.

See the ReplicationConfiguration properties page for a full list of supported options.

const bucketName = "yourgloballyuniquebucketnamehere";
const iamUser = "1233445";
const s3Replication = await provider.makeS3Bucket({
name: bucketName,
properties: () => ({
ReplicationConfiguration: {
Role: `arn:aws:iam::${iamUser}:role/examplerole`,
Rules: [
{
Destination: {
Bucket: "arn:aws:s3:::destinationbucket",
StorageClass: "STANDARD",
},
Prefix: "",
Status: "Enabled",
},
],
},
}),
});

Request Payment#

Set the request payment option for this bucket.

See the RequestPaymentConfiguration properties page for a full list of supported options.

const s3RequestPayment = await provider.makeS3Bucket({
name: `yourgloballyuniquebucketnamehere`,
properties: () => ({
RequestPaymentConfiguration: { Payer: "Requester" },
}),
});

Tags#

Set bucket tags.

const s3Bucket = await provider.makeS3Bucket({
name: "yourgloballyuniquebucketnamehere",
properties: () => ({
Tagging: {
TagSet: [
{
Key: "Key1",
Value: "Value1",
},
{
Key: "Key2",
Value: "Value2",
},
],
},
}),
});

Versioning#

Enable or disable the bucket versioning.

See the VersioningConfiguration properties page

const s3Bucket = await provider.makeS3Bucket({
name: "yourgloballyuniquebucketnamehere",
properties: () => ({
VersioningConfiguration: {
MFADelete: "Disabled",
Status: "Enabled",
},
}),
});

Static Website#

Set the S3 bucket as a website.

See the WebsiteConfiguration properties page for a full list of supported options.

const s3Bucket = await provider.makeS3Bucket({
name: "yourgloballyuniquebucketnamehere",
properties: () => ({
ACL: "public-read",
WebsiteConfiguration: {
ErrorDocument: {
Key: "error.html",
},
IndexDocument: {
Suffix: "index.html",
},
},
}),
});

Examples Code#

Properties#

AWS CLI#

List the S3 buckets for the current account:

aws s3 ls

Remove the bucket and all its content:

aws s3 rb --force s3://yourbucketnamehere