How do I enable versioning on an AWS S3 bucket?
In this guide, we’ll walk you through the process of enabling versioning on an AWS S3 bucket. Versioning allows you to preserve, retrieve, and restore every version of every object stored in your S3 bucket.
Here’s how to define an S3 bucket with versioning enabled:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.s3.BucketV2("example", {
bucket: "my-versioned-bucket",
versionings: [{
enabled: true,
}],
tags: {
Name: "MyBucket",
Environment: "Dev",
},
});
export const bucketId = example.id;
export const bucketArn = example.arn;
In this example, we:
- Specify the AWS provider and region.
- Define an S3 bucket resource with a unique bucket name.
- Enable versioning on the bucket by setting
enabled
totrue
within theversioning
block. - Apply tags to the bucket for easy identification.
- Output the bucket’s ID and ARN for further usage.
Concluding, we have successfully created an AWS S3 bucket with versioning enabled, along with outputs to track the bucket’s details.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.