Day 43: S3 Programmatic access with AWS-CLI πŸ’» πŸ“

Day 43: S3 Programmatic access with AWS-CLI πŸ’» πŸ“

Β·

4 min read

Hi, I hope you had a great day yesterday. Today as part of the #90DaysofDevOps Challenge we will be exploring most commonly used service in AWS i.e S3.

S3

  • Amazon Simple Storage Service (S3) offers a highly scalable and secure object storage solution for various data needs, including:

1 . Text file

2 . Image

3 . Video

4 . Backups & more!

Task-01

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

  • Go to the AWS Management Console and navigate to EC2.

  • Click on "Launch Instance" and follow the steps to launch a new EC2 instance. Choose an appropriate AMI, instance type, and configure security groups to allow SSH access.

  • Once the instance is running, Open a terminal on your local machine.

  • Use SSH to connect to the EC2 instance.

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

  • Go to the S3 console in the AWS Management Console.

  • Click on "Create bucket" and follow the prompts to create a new S3 bucket. Choose a unique name and the region where you want to create the bucket and rest of them keep default and click on create bucket.

  • Once the bucket is created, click on it and then click on "Upload" to upload a file from your local machine to the bucket and click on upload.

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

  • On the EC2 instance terminal, install the AWS CLI if it's not already installed:
sudo apt-get install awscli -y

  • Configure the AWS CLI with your access key ID and secret access key using aws configure as we did in the previous task. You can follow this Task to create a access key ID & secret access key Day-42.
aws configure && aws configure list

  • Check the list of s3 and use the aws s3 cp command to copy the file from the S3 bucket to your EC2 instance:
aws s3 ls

aws s3 cp s3://<bucketname>/<content> /home/ubuntu

Note: To view the contents of your S3 bucket, navigate to your S3 console. On the left side, click on 'Buckets,' then select the name of your bucket that you created. Copy the name of the file which you uploaded your content and paste it into the command.

Task-02

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

  • Go to the EC2 dashboard and select the running instance and Click on "Actions" -> "Image and templates" -> "Create Image" to create a snapshot (AMI) of the instance.

  • After that "create image" page will open there you have to create a image name, description and rest of them keep default and click on create image.

  • Go to the AMIs section in the EC2 dashboard and select the snapshot you created and Click on "Launch instance for AMI" to launch a new EC2 instance from the snapshot.

  • Follow the prompts to configure the instance details, such as instance type, AMI keep it as recent > recently created, security groups, and key pair and click on launch instance.

Download a file from the S3 bucket using the AWS CLI.

  • Connect to the new EC2 instance using SSH.

  • Install and configure the AWS CLI and configure as done previously with same Access key & Secret access key.
sudo apt-get update && sudo apt-get install awscli -y
aws configure

  • Use the aws s3 cp command to download the file from the S3 bucket to the new EC2 instance as you did in the task1.
aws s3 cp s3://<bucketname>/<content> /home/ubuntu

Verify that the contents of the file are the same on both EC2 instances.

  • Check the contents of the file downloaded from S3 on both EC2 instances to ensure they are the same.

Note: In this case i choose .png but you choose text file, videos, etc...


Happy Learning

Thanks For Reading! :)

-Sri ParthuπŸ’πŸ’₯

Β