Day 43: S3 Programmatic access with AWS-CLI ๐Ÿ’ป

Day 43: S3 Programmatic access with AWS-CLI ๐Ÿ’ป

ยท

5 min read

This is #90DaysofDevops challenge under the guidance of Shubham Londhe sir.

Introduction

Welcome to Day 43 of the #90DaysofDevOps Challenge! Today, we're delving into Amazon Simple Storage Service (Amazon S3), a fundamental service in AWS that revolutionizes data storage on the cloud.

Understanding S3:

Amazon S3, or Amazon Simple Storage Service, is a cloud-based storage service provided by Amazon Web Services (AWS). It offers a secure and scalable platform for storing and accessing data over the internet. Here's a deeper dive into its key features:

  1. Object Storage: Amazon S3 is based on object storage, which means it stores data as objects rather than in a traditional file system hierarchy. Each object consists of data, metadata (information about the data), and a unique identifier.

  2. Secure Storage: S3 provides robust security features to protect your data. This includes encryption options for data at rest and during transit, access control mechanisms using AWS Identity and Access Management (IAM) policies, and support for access logging and monitoring.

  3. Scalability: S3 is designed to scale effortlessly to accommodate growing amounts of data. You can store virtually unlimited amounts of data in S3 without worrying about managing hardware infrastructure or capacity planning.

  4. Durability and Availability: Amazon S3 offers high durability and availability for your data. It stores multiple copies of your data across multiple data centers within a region, ensuring that your data remains accessible even in the event of hardware failures or other disruptions.

  5. Versatile Storage: S3 is versatile and supports various types of data, including text files, images, videos, databases, backups, and more. You can use it as a primary storage solution for your applications or as a backup and archival storage repository.

  6. Integration and Compatibility: S3 seamlessly integrates with other AWS services and third-party applications. This enables you to leverage S3 as a storage backend for various use cases, such as hosting static websites, serving media content, storing application logs, and backing up data from on-premises environments.

    Upload Files to S3 with AWS CLI: A Comprehensive Guide

Task-01:

  1. Launch an EC2 Instance:

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

    • Click on "Launch Instance" to start the instance creation wizard.

    • Choose an Amazon Machine Image (AMI), instance type, configure instance details, add storage, configure security groups, and review.

    • Finally, launch the instance and create a new key pair or use an existing one to establish SSH access.

  2. Create an S3 Bucket and Upload a File:

    • From the AWS Management Console, navigate to the S3 service.

    • Click on "Create bucket" and provide a unique name and choose the region for the bucket.

    • Configure additional settings such as versioning, logging, and tags as needed.

    • After creating the bucket, use the console to upload a file to it.

  3. Access the File from the EC2 Instance using AWS CLI:

    • Log in to the EC2 instance using SSH and the key pair generated earlier.

    • Install the AWS CLI on the EC2 instance if not already installed.

    • Use the AWS CLI to download the file from the S3 bucket to the EC2 instance's local file system.

    • Here are some commonly used AWS CLI commands for Amazon S3:

        aws s3 ls        # Lists all S3 buckets in your AWS account.
        aws s3 mb s3://bucket-name   # Creates a new S3 bucket with the specified name.
        aws s3 rb s3://bucket-name   # Deletes the specified S3 bucket.
        aws s3 cp file.txt s3://bucket-name   # Uploads a file to an S3 bucket.
        aws s3 cp s3://bucket-name/file.txt .   # Downloads a file from an S3 bucket to your local file system.
        aws s3 sync local-folder s3://bucket-name   # Syncs the contents of a local folder with an S3 bucket.
        aws s3 ls s3://bucket-name   # Lists the objects in an S3 bucket.
        aws s3 rm s3://bucket-name/file.txt   # Deletes an object from an S3 bucket.
        aws s3 presign s3://bucket-name/file.txt   # Generates a pre-signed URL for an S3 object, granting temporary access.
        aws s3api list-buckets   # Retrieves a list of all S3 buckets in your AWS account, using the S3 API.
      

Task-02:

  1. Create a Snapshot of the EC2 Instance and Launch a New Instance:

    • In the AWS Management Console, navigate to the EC2 service and select the instance you want to snapshot.

    • From the "Actions" dropdown menu, choose "Create Image (AMI)" to create a snapshot of the instance.

    • Provide the necessary details such as name, description, and tags for the snapshot, and then create the AMI.

    • Use the AMI to launch a new EC2 instance with identical configurations.

  2. Download a File from the S3 Bucket using AWS CLI:

    • On the newly launched EC2 instance (from the snapshot), install the AWS CLI if not already installed.

    • Use the following AWS CLI command to download the file from the S3 bucket to the EC2 instance's local file system:

    aws s3 cp s3://your-bucket-name/your-file.txt /path/to/save

  • Replace your-bucket-name with the name of your S3 bucket and your-file.txt with the name of the file you want to download.

  • Specify the local path /path/to/save where you want to save the file on the EC2 instance's file system.

  • Verify that the contents of the file downloaded are the same as the original file on the first EC2 instance.

By mastering S3 programmatic access with AWS CLI, you can efficiently manage and manipulate data in your AWS environment. Stay tuned for more insights and challenges as we continue our DevOps journey together! Feel free to dive into the blog for detailed explanations and guidance. Happy coding! ๐Ÿš€

๐Ÿ’ก
Feel free to drop any questions ๐Ÿค” or requests for help in the comments section! I would be happy to answer them!
๐Ÿ’ก
If you found this information helpful, a thumbs up๐Ÿ‘ and a follow would be greatly appreciated! Your support means the world to me.

Thank you for taking the time to read! ๐Ÿ’š

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!

ย