Day 67: AWS S3 Bucket Creation and Management
In the vast landscape of cloud computing, Amazon Web Services (AWS) has emerged as a prominent player, offering a comprehensive suite of cloud-based solutions to businesses and developers worldwide. Among its fundamental components, the Simple Storage Service (S3) stands out as a crucial pillar, providing a highly scalable and secure object storage infrastructure for managing data. As we delve into Day 67 of our AWS learning journey, we embark on a comprehensive exploration of the intricate process of creating and managing AWS S3 buckets.
AWS S3 Bucket
Amazon S3 (Simple Storage Service) is an object storage service that offers industry-leading scalability, data availability, security, and performance. It can be used for a variety of use cases, such as storing and retrieving data, hosting static websites, and more.
Why to use S3 Bucket
AWS S3 buckets offer several compelling advantages that make them an attractive option for various use cases. Here are some key reasons why businesses and developers choose to use AWS S3 buckets-
- Scalability: AWS S3 provides virtually limitless scalability, enabling users to store and retrieve any amount of data without worrying about capacity constraints. This makes it ideal for handling large-scale data storage requirements and accommodating fluctuating storage needs over time.
- Durability and Reliability: S3 is designed to deliver 99.999999999% (11 nines) durability for objects, ensuring high data reliability. It replicates data across multiple facilities and geographic regions, reducing the risk of data loss and ensuring data availability even in the event of hardware failures, natural disasters, or other disruptions.
- Security: AWS S3 offers various security features, including access control mechanisms, encryption, and secure transfer protocols, to safeguard data at rest and in transit. It allows users to implement security best practices and compliance requirements, ensuring the protection of sensitive data stored within S3 buckets.
- Versatility: S3 supports a wide range of use cases, such as data backup and recovery, media storage and distribution, hosting static websites, application data storage, and big data analytics. Its versatility makes it suitable for various industries, including e-commerce, media and entertainment, healthcare, finance, and more.
- Ease of Use and Integration: AWS S3 integrates seamlessly with other AWS services and third-party applications, allowing for easy data transfer and integration into existing workflows. Its simple and intuitive interface, along with robust API support, simplifies the process of uploading, managing, and accessing data within S3 buckets.
Tasks
In this task, you will learn how to create and manage S3 buckets in AWS.
Task 1) Create an S3 bucket using Terraform.
Install terraform on your ec2 instance. In main.tf file copy below code
provider "aws" {
region = "us-east-1"
access_key = "MyAccesskey"
secret_key = "MySecretkeys"
}
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-day67-bucket-radhey"
}
Apply the terraform commands
terraform init
terraform plan
terraform apply
Our configuration has been successfully done.
Let’s check whether the bucket has been created in AWS.
Yes, Our s3 bucket has been created.
Task 2) Configure the bucket to allow public read access.
- You have to give permissions for your IAM user.
- Go to IAM console and select your user. In Permission policies click on create inline policy for user.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "UpdateS3BucketPolicy",
"Effect": "Allow",
"Action": [
"s3:PutBucketPolicy"
],
"Resource": [
"arn:aws:s3:::my-day67-bucket-radhey"
]
}
]
}
Task 3) Create an S3 bucket policy that allows read-only access to a specific IAM user or role.
provider "aws"{
region = "ap-south-1"
}
resource "aws_s3_bucket" "my_bucket" {
bucket = "day67taskbucketradheyzunjur"
}
resource "aws_s3_bucket_acl" "bucket_acl" {
bucket = aws_s3_bucket.my_bucket.id
acl = "public-read"
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.my_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 = ["683633011377"]
}
actions = [
"s3:GetObject",
"s3:ListBucket",
]
resources = [
aws_s3_bucket.my_bucket.arn,
"${aws_s3_bucket.my_bucket.arn}/*",
]
}
}
Apply terraform apply
S3 bucket policy is created that allows read-only access to a specific IAM user.
Task 4) Enable versioning on the S3 bucket.
The versioning block is included, with enabled set to true. This enables versioning on the S3 bucket, which will keep multiple versions of each object stored in the bucket.
Bucket Versioning is Enabled.