Welcome back to the 90 Days of DevOps journey! Today, we're diving into AWS S3 (Simple Storage Service) bucket creation and management using Terraform.
๐ Question: What is an S3 bucket?
An S3 bucket is a fundamental component of Amazon Web Services (AWS) for storing and retrieving data. Think of it as a folder in the cloud where you can store any type of data โ from documents and images to videos and application backups. S3 buckets are highly scalable, durable, and secure, making them essential for various cloud-based applications and architectures.
๐ ๏ธ Solution with Terraform Files:
Let's walk through the tasks step by step using Terraform, an Infrastructure as Code (IaC) tool that allows us to define and provision AWS resources in a repeatable and automated manner.
1. Create an S3 bucket using Terraform:
resource "aws_s3_bucket" "my_bucket" {
bucket = "your-bucket-name"
}
2. Configure the bucket to allow public read access:
resource "aws_s3_bucket_acl" "public_access" {
bucket = aws_s3_bucket.my_bucket.id
acl {
permissions = "public-read"
}
}
3. Create an S3 bucket policy for read-only access to a specific IAM user or role:
resource "aws_s3_bucket_policy" "readonly_policy" {
bucket = aws_s3_bucket.my_bucket.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Effect = "Allow",
Principal = {
AWS = "arn:aws:iam::ACCOUNT_ID:user/USERNAME" # Replace with IAM user ARN
},
Action = "s3:GetObject",
Resource = "${aws_s3_bucket.my_bucket.arn}/*"
}]
})
}
4. Enable versioning on the S3 bucket:
resource "aws_s3_bucket_versioning" "versioning" {
bucket = aws_s3_bucket.my_bucket.id
versioning {
enabled = true
}
}
By following these steps and executing the Terraform configuration, you'll have successfully created an S3 bucket with public read access, enforced a read-only policy for a specific IAM user or role, and enabled versioning for the bucket.
Keep exploring AWS and DevOps with us on this 90-day journey! Stay tuned for more exciting content and hands-on tutorials. Happy coding! ๐
Feel free to leave your comments, questions, or feedback below. Let's learn and grow together! #AWS #Terraform #S3 #DevOps #InfrastructureAsCode #90DaysOfDevOps
Keep up with the latest DevOps trends and tutorials on my Hashnode blog. Don't forget to follow me for updates! ๐โจ