Day 43 of #90daysofdevops
Hey Techies! Welcome to this blog
In this blog, we are going to start with S3 Programmatic access with AWS-CLI π» π
S3
Amazon Simple Storage Service (Amazon 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.
In this blog post, we will explore how to leverage AWS Command Line Interface (AWS CLI) for programmatic access to S3. We'll cover two tasks that involve launching an EC2 instance, creating an S3 bucket, uploading and accessing files, creating EC2 snapshots, and downloading files from S3 using the AWS CLI.
Task-01
Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH).
Create an S3 bucket and upload a file to it using the AWS Management Console.
Access the file from the EC2 instance using the AWS Command Line Interface (AWS CLI).
Step 1: Launch an EC2 Instance
Log in to the AWS Management Console.
Navigate to the EC2 service.
Click on "Launch Instance" and follow the wizard to configure your EC2 instance.
Download the key pair and launch the instance.
Step 2: Connect to the EC2 Instance
Open a terminal window.
Use the downloaded key pair to SSH into the EC2 instance:
ssh -i path/to/keypair.pem ec2-user@<your-instance-ip>
Step 3: Create an S3 Bucket and Upload a File
In the AWS Management Console, go to the S3 service.
Click "Create Bucket" and follow the prompts to create a bucket.
Upload a file to the bucket.
Step 4: Access the File from the EC2 Instance using AWS CLI
- Install AWS CLI on the EC2 instance:
You can check the previous blog for the AWS CLI installation
- Configure AWS CLI with your credentials:
aws configure
- Use the following command to copy the file from S3 to the EC2 instance:
aws s3 cp s3://your-bucket-name/your-file.txt /path/on/ec2/instance/
Task-02: Creating EC2 Snapshots and Downloading from S3
Step 1: Create a Snapshot of the EC2 Instance
In the AWS Management Console, navigate to the EC2 service.
Right-click on your running instance, select "Create Image," and follow the prompts to create a snapshot.
Step 2: Launch a New EC2 Instance from the Snapshot
- In the AMIs section of the EC2 service, launch a new instance using the created snapshot.
Step 3: Download a File from S3 Using AWS CLI
On the new EC2 instance, install and configure AWS CLI as in Task-01.
Use the following command to download the file from S3:
aws s3 cp s3://your-bucket-name/your-file.txt /path/on/ec2/instance/
Step 4: Verify Contents on Both EC2 Instances
- Compare the contents of the file on both EC2 instances:
diff /path/on/first/ec2/instance/your-file.txt /path/on/second/ec2/instance/your-file.txt
This command will show no output if the files are identical.
That's it! You've just completed the task. π
Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.
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.
Happy Learning!
~kritika :)
Connect with me: LinkedIn