Day 43- 90DaysOfDevOps

S3 Programmatic access with AWS-CLI

Day 43- 90DaysOfDevOps

Hey Learners! Welcome back. I hope you had a great journey till the time with our #90DaysOfDevOps challenge. Today as part of this challenge we will explore the most commonly used service in AWS i.e. Simple Storage Service (S3). Let's begin...

Simple Storage Service (S3):-

Amazon Simple Storage Service (S3) is an object storage service that provides a secure and scalable way to store and access data on the cloud. It is designed for storing any kind of data, such as text files, images, videos, backups, and more.

Task 1-

Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH)

We all know how to launch an instance and connect to it using SSH.

Note- See previous challenge for Launch instance(Do not enter UserData).

Create an S3 bucket and upload a file to it using the AWS Management Console.

To create an S3 bucket first Log in to the AWS console and search for S3 service. From the S3 management console select Buckets from the Left navigation pane and click Create bucket.

Enter the unique name for the bucket select the region where you want to create a bucket and click Create bucket.

After successfully creating a bucket select the bucket name and you will see the Upload option to upload files in that bucket. Add some files

Click on Upload and select Add files select the files you want to store in to bucket select the files that you added and finally click on Upload.

You can select the bucket as previously and you will see the files added are stored there in the bucket.

Access the file from the EC2 instance using the AWS Command Line Interface (AWS CLI)

I am going to demonstrate directly on my Machine not on the EC2 instance.

First Check whether AWS CLI is installed or not on the Machine using the aws --version command and configure the AWS CLI.

Note if AWS CLI is not installed refer previous challenge click(DAY42LINK) here to see.

Tom list all S3 bucket with AWS CLI using aws s3 ls command. To copy content from the bucket to local use aws s3 cp s3://<bucketname>/<content> <home/path> command. Refer below screenshot for a better understanding.

This is how we can use AWS CLI to manage AWS resources from CLI.

Task 2-

Create a snapshot of the EC2 instance and use it to launch a new EC2 instance

Select Snapshots from the left navigation pane and click Create snapshot

Select Resource Type as Instance and select the instance you want to create a snapshot of. Scroll down and Click Create Snapshot.

Your snapshot is successfully created.

You can directly create an instance from this snapshot. Select the snapshot you created earlier Go to Actions and select Create image from snapshot.

Enter the name of the Image and description for the image. Scroll down and select Create Image.

Go to the AMIs section in the left navigation pane select the AMI listed and select Launch instance from AMI. Proceed with the steps to Launch the instance.

Download a file from the S3 bucket using the AWS CLI

Use the aws s3 cp command as used in Task 1 of this challenge to download a file from a S3 bucket. Refer to Task 1.

Some AWS CLI commands for S3:-

aws s3 ls
To list all the buckets present in your AWS account
aws s3 ls s3://<bucket-name>
To list objects present in an S3 bucket
aws s3 mb s3://<new-bucket-name>
To create a new S3 bucket with a specified name
aws s3 rb s3://<bucket-name>
To delete the specified bucket from the AWS account
aws s3 cp <file-name> s3://<bucket-name>
To upload specified files to the S3 bucket
aws s3 cp s3://<bucket-name>/<file-name> <local/path>
To download specified files from the bucket to the local

If you want to delete a bucket which contains some objects/files in it then you have to use the --f flag with the rb command.

This is about S3 service and how we can manage S3 service via AWS CLI.

Thank you so much for taking the time to read till the end! Hope you found this blog informative.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Find me on:- Hashnode LinkedIn Github

Happy Learning!