S3 Programmatic access with AWS-CLI đź’»

This is Day 43 of #90daysofdevops challenge

S3 Programmatic access with AWS-CLI đź’»

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.

What is AWS S3?

AWS S3 stands for Amazon Simple Storage Service. It is Amazon's cloud storage service for storing and retrieving any amount of data from the cloud.

Some key points about AWS S3:

  • It is a simple object storage service, which means you store files as objects with a unique URL.

  • It provides 11 9's of durability, meaning your data is extremely durable and unlikely to be lost.

  • It offers high availability and scalability. It can scale to exabytes of data and to millions of requests per second.

  • Data is stored across multiple Availability Zones for high availability.

Some common use cases for S3 are:

  • Storing static websites

  • Serving images/videos/files to applications

  • Storing backups and archives

  • Collecting logs from AWS services

Task 1: AWS EC2 and S3 Interaction

  • Launch an EC2 instance using the AWS Management Console and connect to it using Secure Shell (SSH).
  1. Log in to AWS Console: Go to the AWS Management Console and log in to your AWS account.

  2. Launch an EC2 Instance:

    • Navigate to the EC2 service.

    • Click on "Instances" in the left sidebar.

    • Click the "Launch Instances" button to create a new EC2 instance.

    • Follow the instance creation wizard, selecting an Amazon Machine Image (AMI), configuring instance details, adding storage, configuring security groups (allow SSH traffic), and reviewing your settings.

    • Launch the instance and create or select an existing key pair to use for SSH access.

  3. Connect to the EC2 Instance:

    • Once your EC2 instance is running, select it in the EC2 dashboard.

    • Click the "Connect" button to view instructions for connecting via SSH. Use the provided SSH command, replacing your-key.pem with the path to your private key file.

    • For example:

        ssh -i /path/to/your-key.pem ec2-user@ec2-instance-public-ip
      
  • Create an S3 bucket and upload a file to it using the AWS Management Console.

  • Navigate to the S3 service in the AWS Management Console and Click the "Create bucket" button.

  • Choose a unique bucket name, select a region, and configure any additional settings as needed.

  • Create the bucket.

  • The S3 bucket is created now.

Upload a File to the S3 Bucket:

  • Inside your newly created S3 bucket, click the "Upload" button.

  • Select the file you want to upload from your local machine and follow the upload wizard.

  • The file is now uploaded to the S3 bucket.

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

Install AWS CLI on EC2:

  • If it's not already installed on your EC2 instance, you can install the AWS CLI by running:
sudo apt-get update
sudo apt-get install awscli -y

Once you installed AWS CLI use aws --version to check AWS CLI version.

Now, configure your aws by using aws configure command and enter your AWS access key id and Secret access key.

Now, list s3 bucket using aws s3 ls command:

If you want to download the files present in your s3 bucket for that you can use aws s3 cp command to download the files.

Task 2: EC2 Snapshot and S3 File Verification Task

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

  • Navigate to AWS EC2 service and click on “Snapshots”

  • Now, click on "create snapshot"

  • Select the EC2 instance that you want to create a snapshot.

  • Click on "create snapshot"

  • Snapshot created.

  • Click on the "Actions" button present on the right side and choose "Create Image from snapshot" from the drop-down menu.

  • In the “Create Image from snapshot” window, enter a name and description for the image.

  • Now, click on "Create image"

  • Go to the "AMI" section on the EC2 dashboard and check if image is created or not.

  • Now click on "Launch instances from AMI"

  • Connect to instance using SSH and use this command:
<aws s3 cp s3://bucket-name/file.txt .> - This command downloads a file from an S3 bucket to your local file system.

"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.

Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/) for the latest updates and discussions.

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!

Â