Day 67 Task: AWS S3 Bucket Creation and Management

Day 67 Task: AWS S3 Bucket Creation and Management

ยท

2 min read

S3 bucket: Hands-On

  • Create an S3 bucket using Terraform

  • Create an S3.tf with required bucket name.
resource "aws_s3_bucket" "my_bucket" { 
  bucket = "day67s3bucketnew"
}
  • Use terraform init and plan to get the providers and view the terraform changes.

  • Now, use terraform apply to make the changes using terraform files.

  • Navigate to the AWS management console and go to S3 to view the bucket created.

Configure the bucket to allow public read access

  • Enable the ACL in the S3 bucket and choose Bucket owner preferred and save the change.

resource "aws_s3_bucket_public_access_block" "example" {
                bucket = aws_s3_bucket.my_bucket.id

                block_public_acls       = false
                block_public_policy     = false
                ignore_public_acls      = false
                restrict_public_buckets = false
              }
resource "aws_s3_bucket_acl" "bucket_acl" {
                bucket = aws_s3_bucket.my_bucket.id
                acl    = "public-read"
              }
  • Create a public_access.tf file and write proper configuration.

  • Use terraform apply to create public access for the S3 bucket.

  • Check the bucket in the console for the public access which is now enabled.

Create an S3 bucket policy that allows read-only access to a specific IAM user or role

  • Create an main.tf file to write the configuration of IAM read access for the S3 bucket.

  • Now, use terraform apply to provide the access in the bucket.

  • Now, check the bucket to view the policy.

Enable versioning on the S3 bucket

  • Insert the versioning configuration in the S3.tf file.

resource "aws_s3_bucket" "my_bucket" {
    bucket = "day67s3bucketnew"
    versioning {
      enabled = true
    }
  }
  • Use the terraform apply to enable versioning in S3 bucket.

  • We can see the changes in the S3 bucket in the AWS management console.

๐Ÿ”ถ Conclusion:

In conclusion, this blog has walked you through the essential steps of creating and managing an AWS S3 bucket using Terraform. We started by defining the S3 bucket configuration in the S3.tf file, enabling versioning to enhance data protection and retrieval capabilities.

By executing terraform apply, you brought your infrastructure to life, creating the S3 bucket as specified. The final step, a quick verification of versioning settings, ensures that your bucket is configured as intended.

I hope this blog has been a valuable resource in your journey to mastering cloud technologies.

Happy Learning :)

If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐Ÿš€ #devops #90daysofdevop #AWS

ย