S3 Programmatic access with AWS-CLI ๐Ÿ’ป๐Ÿ“

S3 Programmatic access with AWS-CLI ๐Ÿ’ป๐Ÿ“

ยท

7 min read

Introduction

In today's task, we dive into the seamless integration of Amazon Elastic Compute Cloud (EC2) and Simple Storage Service (S3) in AWS. This essential synergy enables efficient file transfers between instances, providing a powerful foundation for data management.

S3 in AWS

Amazon Simple Storage Service (Amazon S3) is a scalable object storage service provided by Amazon Web Services (AWS). It allows you to store and retrieve virtually unlimited amounts of data over the internet. S3 is designed to be highly durable, meaning that it ensures the safety and security of your data.

For detailed information and usage instructions, you can refer to the official Amazon S3 documentation.

Features of S3

Key FeatureDescription
Scalable StorageAmazon S3 provides virtually limitless storage capacity, allowing you to store vast amounts of data.
DurabilityS3 is designed to provide 99.999999999% (11 9's) durability, ensuring that your data remains safe and accessible.
SecurityIt offers robust security features, including encryption, access control lists, and bucket policies, to protect your data.
Data ManagementS3 allows you to manage your data with features like versioning, which enables the storage of multiple versions of an object.
Storage ClassesS3 offers different storage classes optimized for various use cases, allowing you to balance cost and performance.
Static Website HostingS3 can host static websites, making it a cost-effective solution for hosting web content.
Content DeliveryWhen combined with Amazon CloudFront, S3 provides low-latency, high-speed content delivery through a global network of edge locations.
Lifecycle PoliciesYou can define rules to automatically transition or expire objects, optimizing storage costs.
Cross-Region ReplicationS3 enables automatic replication of objects to different AWS regions for redundancy and compliance with data residency requirements.
Analytics and ReportingS3 offers features for tracking, analyzing, and reporting on object storage access patterns.
Object VersioningS3 allows you to keep multiple versions of an object, providing an additional layer of data protection.
Data Transfer AccelerationThis feature enables fast, secure transfers of data over long distances.
Multipart UploadsFor large objects, S3 supports multipart uploads, allowing for efficient uploading and downloading.
Query-in-PlaceS3 Select and Glacier Select allow you to run queries on the data stored in S3, reducing the amount of data that needs to be retrieved.
Data Governance and ComplianceS3 provides features like Object Lock and AWS Macie for enhanced data governance and compliance with regulatory requirements.
Data ArchivingS3 integrates with Amazon Glacier, providing cost-effective archiving solutions for data that is rarely accessed.
Access Control LoggingYou can monitor and log requests made to your S3 buckets, helping with compliance audits and troubleshooting.
Server Access LoggingYou can track requests for access to your bucket and its objects.

Amazon S3 is an essential and flexible service in the AWS cloud that allows for data storage and management, catering to a wide range of industries and use cases.

Storage classes offered by Amazon S3

Amazon S3 offers several storage classes to cater to different use cases and optimize costs. Here are the main ones:

  1. S3 Standard: Ideal for frequently accessed data with high availability and low latency.

  2. S3 Intelligent-Tiering: Automatically moves objects between Standard and Standard-IA based on access patterns.

  3. S3 Standard-IA (Infrequent Access): For data accessed less frequently, but still requires high availability.

  4. S3 One Zone-IA: Similar to Standard-IA but stores data in a single availability zone, reducing costs.

  5. S3 Glacier (S3 Select, S3 Restore): Suitable for long-term archival with flexible retrieval options.

  6. S3 Glacier Deep Archive: The lowest cost storage class for long-term retention of data.

  7. S3 Outposts: Designed for AWS Outposts, offering object storage on-premises.

  8. S3 Reduced Redundancy Storage (RRS): Legacy storage class with lower durability, being phased out.

For more detailed information on Amazon S3 storage classes, you can visit the official AWS S3 documentation.

What are the pricing options for Amazon S3?

Amazon S3 Pricing:

  • Storage: Pay for stored data.

  • Requests: Charges for different types of actions.

  • Data Transfer: Fees for moving data.

  • Acceleration: Additional cost for fast transfers.

  • Replication: Charges for cross-region copies.

  • Lifecycle: Costs for object transitions.

  • Storage Classes: Each has unique costs.

  • Retrieval (select classes): Fees for accessing data.

For detailed pricing information, visit the AWS S3 Pricing Page.

New users enjoy a limited free tier for the first 12 months.

Tasks:)

๐Ÿ”—Task : Creating an S3 Bucket in AWS Management Console

  1. Log in to AWS Console:

  2. Navigate to S3:

    • In the AWS Management Console, search for and select "S3" to open the S3 dashboard.

  3. Create a Bucket:

    • Click on the "Create bucket" button.

  4. Configure Bucket:

    • Enter a unique bucket name.

    • Select the AWS Region where you want to create the bucket.

    • Configure other settings like:-

      • Object Ownership: Configure object ownership settings to define which AWS account will be the object owner.

      • Block Public Access Settings for This Bucket: These settings allow you to configure restrictions on public access to your bucket and its objects, helping to prevent unauthorized access.

      • Bucket Versioning: Enable this feature to keep multiple versions of an object in the same bucket. It helps protect against accidental deletion or overwriting of objects.

  5. Review and Create:

    • Review the settings and click "Create bucket" to complete the process.

๐Ÿ”—Task : Integrating EC2 and S3 for File Transfer

  1. Launch EC2 Instance:

    • Use AWS Management Console to launch an EC2 instance.

    • Connect to it via Secure Shell (SSH).

  2. Create S3 Bucket & Upload File:

    • Open the previously created S3 bucket.

    • Click on the "Upload" button to upload a file from your local system to the bucket.

    • Follow the prompts to select and upload the desired file.

    • Once uploaded, verify that the file appears in the S3 bucket.

  3. Access S3 File from EC2:

    • Check AWS CLI Installation:

    • List S3 Bucket Contents:

      • First login to the aws using cli

          aws configure
        

        then enter your credential

      • Use the command aws s3 ls to list the contents of your S3 bucket.

          aws s3 ls
        

    • Copy S3 File to EC2:

      • To copy a file from S3 to your EC2 instance, use the command aws s3 cp s3://your-bucket-name/your-file-path /path-to-destination-on-ec2/.

          aws s3 cp s3://your-bucket-name/your-file-path /path-to-destination-on-ec2/.
        

    • Verify the Copy:

      • Confirm that the file has been copied to your EC2 instance.

๐Ÿ”—Task : EC2 Snapshot, S3 Download, and Verification

  1. 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".

    • Click on "Create Snapshot".

    • Select the EC2 instance for the snapshot and click "Create Snapshot".

    • Once the snapshot is created, go to "Actions" > "Create Image from Snapshot", provide a name and description, then click "Create image".

    • Go to the "AMI" section on the EC2 dashboard to verify if the image is created.

      you will see that image that you created, select them.

  2. Launch the instance

  3. Connect the instance

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

    • Enter your credential for login

        aws configure
      
    • Use the command: aws s3 cp s3://bucket-name/file.txt . to download a file from an S3 bucket to your local file system.

        aws s3 cp 3://bucket-name/file.txt .
      

  5. Verify that the contents

Conclusion :)

With the successful integration of EC2 and S3, you've gained a powerful capability for data transfer and management within your AWS environment. This dynamic duo opens up a world of possibilities for your DevOps endeavors.


Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps ๐Ÿš€, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!

Feel free to connect with me on:

LinkedIn

Twitter

GitHub

For more updates and engaging discussions on DevOps, let's connect! ๐Ÿš€ #DevOpsCommunity

Happy Learning! Keep pushing those boundaries! ๐Ÿ˜Š

ย