Day 43 of 90 Days of DevOps Challenge: S3 Programmatic Access with AWS CLI

S3

Amazon Simple Storage Service (Amazon S3) is a widely used object storage service that offers secure and scalable storage in the cloud. It can store any type of data, including text files, images, videos, backups, and much more. It’s essential for data storage in cloud architectures and often plays a key role in DevOps workflows.

You can learn more about Amazon S3 here.


Today's Tasks

Task 1: Launch an EC2 Instance and Upload a File to S3

Step-by-Step Guide:

  1. Launch an EC2 Instance:

    • Open the AWS Management Console and go to EC2.

    • Click Launch Instance and choose Amazon Linux 2 AMI.

    • Select t2.micro as the instance type.

    • Configure instance details (leave defaults for now) and click Review and Launch.

    • Once the instance is running, connect via SSH using your key pair:

        ssh -i your-key.pem ec2-user@your-ec2-public-ip
      

  1. Create an S3 Bucket:

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

    • Click Create bucket and enter a globally unique name.

    • Choose your preferred region and configure the rest as default.

    • Click Create bucket.

  2. Upload a File to S3:

    • Open your created bucket.

    • Click Upload and choose a file from your local machine.

    • Upload the file to the bucket.

  3. Access the File from EC2 Using AWS CLI:

    • From your EC2 instance, configure AWS CLI if you haven't already (run aws configure).

    • Run the following command to retrieve the file:

        aws s3 cp s3://your-bucket-name/your-file-name .
      
    • This will download the file to your EC2 instance.

  4. Verify File Access:

    • Use the ls command to check the file:

        ls
      


Task 2: Create a Snapshot of EC2 Instance and Use It to Launch a New EC2 Instance

Step-by-Step Guide:

  1. Create a Snapshot of Your EC2 Instance:

  2. Launch a New EC2 Instance from Snapshot:

  3. Download the File from S3 on the New EC2 Instance:

    • Once the new instance is up and running, connect to it via SSH.

    • Install and configure AWS CLI on the new instance (if not already configured):

        curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
        unzip awscliv2.zip
        sudo ./aws/install
      
    • Download the same file from the S3 bucket:

        aws s3 cp s3://your-bucket-name/your-file-name .
      
  4. Verify File Contents:

    • Use the ls command again to check the file:

        ls
      

Conclusion

Today, you learned about S3 programmatic access using the AWS CLI. You explored how to:

  • Launch EC2 instances,

  • Upload and access files from S3,

  • Use AWS CLI to perform essential tasks like file transfer between S3 and EC2 instances, and

  • Create and utilize EC2 Snapshots for data preservation and launching new instances.

This hands-on experience with S3 and EC2 automation expands your cloud skillset and enhances your ability to manage AWS resources effectively. Keep practicing, and see you on the next day of the challenge! 🚀