1. Answers
  2. Enabling Versioning on an AWS S3 Bucket

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:

  1. Specify the AWS provider and region.
  2. Define an S3 bucket resource with a unique bucket name.
  3. Enable versioning on the bucket by setting enabled to true within the versioning block.
  4. Apply tags to the bucket for easy identification.
  5. 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 up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up