Day 67: AWS S3 Bucket Creation and Management ๐Ÿš€

ยท

3 min read

Day 67: AWS S3 Bucket Creation and Management ๐Ÿš€

Welcome back to another exciting day of learning! Today, we're diving into the world of Amazon S3 (Simple Storage Service), a powerful object storage service offered by AWS. With S3, we can store and retrieve data easily, ensuring scalability, security, and top-notch performance for our applications.

What is Amazon S3? Amazon S3, or Simple Storage Service, provides scalable object storage that can handle virtually unlimited amounts of data. It's perfect for storing a wide range of content, including images, videos, documents, and much more. With its high availability and durability, S3 is a go-to solution for many storage needs in the cloud.

Task: Create and Manage an S3 Bucket

Step 1: Create an S3 Bucket Using Terraform We'll start by using Terraform to create our S3 bucket. Terraform's infrastructure as code approach makes it easy to define our resources in a declarative manner. With just a few lines of code, we can have our bucket up and running in no time!

Step 2: Configure Bucket for Public Read Access Next, we'll configure our bucket to allow public read access. This is useful for scenarios where we want to host static assets, such as images or files, that need to be accessible to the public. By setting the appropriate permissions, we can ensure that everyone can access the content stored in our bucket.

Step 3: Create an S3 Bucket Policy To control access to our bucket more granularly, we'll create an S3 bucket policy. This policy will specify who has read-only access to the bucket, ensuring that only authorized users or roles can retrieve data from it. This adds an extra layer of security to our storage solution.

resource "aws_s3_bucket_policy" "bucket_policy" {
  bucket = aws_s3_bucket.devops_bucket.id
  policy = data.aws_iam_policy_document.allow_read_only_access.json
}


data "aws_iam_policy_document" "allow_read_only_access" {
  statement {
    principals {
      type        = "AWS"
      identifiers = ["102923479884"]
    }

    actions = [
      "s3:GetObject",
      "s3:ListBucket",
    ]

    resources = [
      aws_s3_bucket.devops_bucket.arn,
      "${aws_s3_bucket.devops_bucket.arn}/*",
    ]
  }
}

Step 4: Enable Versioning Lastly, we'll enable versioning on our S3 bucket. Versioning allows us to keep multiple versions of an object in the bucket over time. This can be invaluable for tracking changes and recovering from accidental deletions or modifications.

  resource "aws_s3_bucket" "devops_bucket" {
      bucket = "devopsbucketday67"
      versioning {
        enabled = true
      }
    }

By following these steps, we'll have a fully functional S3 bucket that's ready to store and serve our data securely and efficiently. With Terraform's automation capabilities, managing our S3 resources becomes a breeze, freeing up time for more important tasks in our AWS infrastructure. Stay tuned for more adventures in the cloud! โœจ #AWS #S3 #Terraform #CloudStorage #DevOps

Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.

You can connect with me at: https://www.linkedin.com/in/davendersingh/

ย