How to Setup S3 Bucket On AWS Cloud
Setup S3 Bucket on AWS
Amazon Simple Storage Service (Amazon S3)
S3 in simple words is Object storage built to store and retrieve any amount of data from anywhere.
Benefits of S3
- Industry-leading performance, scalability, availability, and durability
- Wide range of cost-effective storage classes
Unmatched security, compliance, and audit capabilities
Easily manage data and access controls
Query-in-place services for analytics
Most supported cloud storage service
Amazon S3 Storage Classes
AWS S3 has few storage classes that can be used on the requirement of storing data.
- S3 Standard
- S3 Intelligent-Tiering
- S3 Standard-Infrequent Access
- S3 One Zone-Infrequent Access
- S3 Glacier
- S3 on Outposts
You can read detailed information about the above storage classes from the AWS portal “https://aws.amazon.com/s3/storage-classes/“.
In this article, I am going to provide you the steps to create an S3 bucket, upload files, & setup lifecycle policy on the AWS cloud.
Step 1: Login AWS Account
The first step is obvious that you need to login to the AWS account to create a bucket or access the S3 service.
If you are a beginner and don’t have access to AWS cloud then there is good news for you. Amazon cloud provides a One Year free subscription to learn the cloud services free of cost.
Go to the below link to set up your first Free AWS Account,
Now click on the link “https://aws.amazon.com/” and then go to the “My Account –> AWS Management Console“.
The login page will open and now put your login details and click on “Sign In“.
Step 2: Create an S3 Bucket
Once you login to the portal, click on the left corner of tab “Services” where you will get all the available services provided by the AWS Cloud.
In Services, go to the Storage & click on S3.
On the S3 portal, you will find a button to “Create Bucket”.
Click on “Create Bucket“.
In Create bucket, there will be 4 stages that you need to complete to create a bucket on S3.
- Name & Region
Here you need to add the Bucket name (Should be unique) and the region where you want the bucket needs to configure.
Once you fill in the details, click on the Next Button.
2. Configure Options
In the second option, you can configure the log and versioning for your S3 bucket objects. Also, you can setup Cloudwatch metrics where you will have metrics for data in/out transfer from your s3 bucket.
Here, we are setting up buckets to store backup files so we don’t require versioning and logs for the same.
Leave all options as it is and click on the “Next” button.
3. Set Permissions
To make your bucket private/secure and restrict access publicly then click on the check box “Block all public access“.
Now in the last step, review all your settings and click on the “Create bucket” button.
Step 3: Add Lifecycle Policy
In the Lifecycle policy, you can define the expiry of the objects or files which are going to store on the S3 bucket.
Like, If you want to store back up for the last 30days only and older than 30days files going to be deleted from the S3 bucket.
Lifecycle policy helps to save costs for s3 bucket by removing the older backup files.
Click on the “bucket” and go to the “Management Tab”. then click on the “Add Lifecycle rule” button.
The lifecycle rule has 4 stages and you need to provide the required information.
- Name and Scope
Here you need to provide the name of the policy and the choice rule scope.
We are choosing the second rule i.e. “Apply to all objects in the bucket“.
In transitions, you need to choose the version of the objects on that basis lifecycle policy will remove the object but here we haven’t used any versioning on the bucket so leave it as it is and click on the “Next” button.
In Expiration, you need to define the expiry period.
Now review all your settings and click on the “Save” button.
After setting up the Bucket on AWS, now we need to create one IAM User who has access to the bucket to upload files.
Let’s start with a further configuration that helps to transfer/upload files from your server to the s3 bucket directly.
Step 4: Create an IAM User
This IAM user would have complete access to the bucket to upload files.
To create a user, go to the AWS “Services –> IAM –> Users“
Click on the “Add User” and create a user as “backupuser”. While creating a user, it will ask you to Select AWS access type.
We will choose “Programmatic Access” that will allow you to access the bucket using AWS CLI commands.
Now just click on “Next Permissions” and click next button until it will provide you the Access Keys to download.
On stage 5, It will provide you the Download.csv file to download i.e. our credentials of IAM User.
Now our IAM user is ready with the username & password.
Step 5: Create A User Policy
To create user policy and assign it to the backupuser.
Go to the AWS “Services -> IAM -> Policies -> Get Started.”
Click on “Create your own policy” then add the below policy. after adding policy first click on “validate policy” then click on “create policy“.
Once you clicked the “Create Policy”, It will provide you two ways to create policy one is “Visual Editor” and another one is “JSON”.
Go to the “JSON” tab and add the below JSON code which will allow access to the S3 bucket.
Now “Review Policy” & on next tab provide Name for the policy.
Click on the Create policy button.
Step 6: Attach Policy
Now Go back to the “Services->IAM->Users” and click on backupuser and attached the above policy for the user.
- Add Permissions -> Attach Policy -> S3BackupUserPolicy
Our s3 bucket is ready to store backup files. This article is part of MySQL DB backup files transfer from server to s3 bucket.
Please refer below link where we have configured the AWS CLI on the server to transfer files from server to s3 bucket, Also I have provided one Mysql Backup script which will take a backup of MySQL databases on daily basis on the server & transfer the backup file to S3 bucket,
If you’re facing any difficulties while configuring the AWS S3 Bucket. Please do comment queries or problems via the comment section, till then stay tuned to Linuxgrow.com for more such valuable articles.