DEV Community

Cover image for Mastering AWS CloudFormation: Creating an S3 Bucket with Versioning Enabled
Bhabna Samantara
Bhabna Samantara

Posted on

Mastering AWS CloudFormation: Creating an S3 Bucket with Versioning Enabled

AWS CloudFormation, a powerful IaC service, allows you to define and provision AWS resources seamlessly. In this step-by-step guide, we will walk through the process of creating an S3 bucket with versioning enabled using AWS CloudFormation.

Step 1: Create a CloudFormation Template
AWS CloudFormation uses templates, written in JSON or YAML, to declare the AWS resources needed for your infrastructure. So Open your favorite text editor and create a new YAML file, for example, s3-bucket.yaml. Define the S3 bucket and enable versioning:

AWSTemplateFormatVersion: "2010-09-09"
Description: Simple cloud formation for bucket creation

Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-unique-bucket-name
      VersioningConfiguration:
        Status: Enabled
Enter fullscreen mode Exit fullscreen mode

In this example, we're creating an S3 bucket named my-unique-bucket-name with versioning enabled.

Step 2: Deploy the CloudFormation Stack
Open the AWS Management Console and navigate to the CloudFormation service.
Click on "Create Stack" and select "Upload a template file."
Upload your s3-bucket.yaml file.
Click "Next," provide a Stack name (e.g., MyS3Bucketstk), and click "Next" through the following screens.
Review the settings and click "Create Stack".

Step 3: Monitor the Stack Creation
As CloudFormation creates your stack, monitor the progress in the CloudFormation console. The stack status will change from "CREATE_IN_PROGRESS" to "CREATE_COMPLETE" upon successful completion.

Image description

Step 4: Verify the Created S3 Bucket
Navigate to the S3 service in the AWS Management Console. You should see a new S3 bucket named my-unique-bucket-name with versioning enabled.

Step 5: Clean Up
In the CloudFormation console, select your stack (MyS3BucketStack) and click "Delete Stack." Confirm the deletion to remove the S3 bucket and associated resources.

Conclusion
You've successfully created an S3 bucket with versioning enabled using AWS CloudFormation. As you explore CloudFormation further, such as tags, access control, and event triggers, tailor your S3 bucket deployment to your specific requirements.

Top comments (0)