DEV Community

Cover image for πŸ—‚οΈ Working with AWS S3 Cloud Storage Services πŸ’Ύ
Madhurima Rawat
Madhurima Rawat

Posted on β€’ Edited on β€’ Originally published at github.com

7 1 2 2

πŸ—‚οΈ Working with AWS S3 Cloud Storage Services πŸ’Ύ

βš™οΈ Hello Deployers! Time to Launch! 🚒✨

May your web app never crash and never stumble into a bug! 🐞🚫

πŸ’Ύ All code, docs, and resources are available in my GitHub repository:

GitHub logo madhurimarawat / Cloud-Computing

This repository focuses on cloud computing and demonstrates how to set up virtual machines, S3, and other services using LocalStack. It provides a comprehensive guide to simulating AWS services locally for development and testing purposes.

Cloud-Computing

This repository focuses on cloud computing and demonstrates how to set up virtual machines, S3, and other services using LocalStack. It provides a comprehensive guide to simulating AWS services locally for development and testing purposes.

Repo Size GitHub Stars GitHub Forks GitHub Issues Closed Issues Open Pull Requests Closed Pull Requests GitHub Discussions GitHub Contributors Top Language License Last Commit Repository Age Workflow Status GitHub Watchers Visitors


Tools and Technologies βš™οΈπŸ’»

1. AWS CLI

AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. It simplifies managing cloud resources by providing commands for a wide range of AWS services, enabling tasks such as provisioning, managing, and automating workflows with ease.

LocalStack is a fully functional, local testing environment for AWS services. It enables developers to simulate AWS services on their local machines, facilitating the development and testing of cloud-based applications without needing access to an actual AWS account.

3. Docker

Docker is a containerization platform that allows developers to build, share, and run applications in isolated environments called…




In the previous article,

we understood how to deploy a Virtual Machine (VM) on a cloud server using LocalStack.

Now, let’s level up and dive into AWS S3 β€” one of the most powerful and essential cloud storage services!

Before we jump into the setup, I’ll explain what S3 is, why it’s useful, and how we can use it for storing files, hosting static websites, backups, and more.

What is AWS S3?

Amazon S3 (Simple Storage Service) is an object storage service that offers scalability, security, and high availability. It allows users to store and retrieve any amount of data at any time, making it ideal for backups, website hosting, and data lakes.

  • Secure and highly available storage solution
  • Supports various storage classes for cost optimization
  • Used for website hosting, backup, and disaster recovery
  • Provides strong access control and encryption options
  • Integrates seamlessly with other AWS services

Use Cases for S3

Amazon S3 is widely used across industries for a variety of purposes, including storing media files, hosting websites, and serving as a data lake for big data analytics.

  • Storing images, videos, and static website assets
  • Hosting static websites and content delivery
  • Backup and disaster recovery solutions
  • Log storage for analytics and monitoring
  • Machine learning and big data storage

S3 Storage Types

Amazon S3 provides different storage classes to meet various needs, balancing cost and performance. Each class is designed for a specific use case, from frequent access to long-term archival.

  • S3 Standard: High durability and performance for frequently accessed data
  • S3 Intelligent-Tiering: Automatically moves data to lower-cost tiers when not accessed
  • S3 Standard-IA (Infrequent Access): Lower cost for data that is accessed less frequently
  • S3 Glacier & Glacier Deep Archive: Cost-effective long-term archival storage
  • S3 One Zone-IA: Lower-cost storage for infrequently accessed data in a single availability zone

Step-by-Step Guide


Step 1: Start LocalStack

Run the following command to start LocalStack:

localstack start
Enter fullscreen mode Exit fullscreen mode

Alternatively, use Docker:

docker run --rm -it -p 4566:4566 localstack/localstack
Enter fullscreen mode Exit fullscreen mode

Start Docker Desktop

  • Launch Docker Desktop and wait until it indicates that "Docker is running."
  • LocalStack will simulate AWS services on port 4566, allowing local cloud development without an actual AWS account.

Step 2: Creating an S3 Bucket in LocalStack

Commands Breakdown:

  1. List Existing Buckets:
   aws --endpoint-url=http://localhost:4566 --region us-east-1 s3 ls
Enter fullscreen mode Exit fullscreen mode
  • Purpose: This command is used to list the existing S3 buckets in your LocalStack environment, running at localhost:4566.
  • Output: No output is shown initially, meaning there are no buckets created at that point.
  1. Create a New S3 Bucket:
   aws --endpoint-url=http://localhost:4566 --region
   us-east-1 s3 mb s3://my-test-bucket
Enter fullscreen mode Exit fullscreen mode
  • Purpose: This command creates a new S3 bucket named my-test-bucket in the LocalStack environment.
  • Output: make_bucket: my-test-bucket β€” This confirms the successful creation of the my-test-bucket.
  1. List Buckets Again:
   aws --endpoint-url=http://localhost:4566 --region us-east-1 s3 ls
Enter fullscreen mode Exit fullscreen mode
  • Purpose: This command lists the existing S3 buckets again, this time after creating the new bucket.
  • Output:

     2025-01-23 13:09:41 my-test-bucket
    

    β€” This confirms that the my-test-bucket is now listed and was successfully created.


Detailed Explanation:

  1. LocalStack’s Purpose:
  • LocalStack emulates AWS services locally, providing an environment for developers to simulate AWS without needing an actual AWS account or incurring costs. It mimics APIs for various services such as S3, EC2, Lambda, etc., making it a useful tool for development and testing.
  1. CLI Commands and Output:
  • The AWS CLI interacts directly with LocalStack through the endpoint localhost:4566, which is where the LocalStack service is running. Every time you run commands like aws s3 mb or aws s3 ls, LocalStack processes these commands as if they were sent to the actual AWS cloud.
  • After running the aws s3 mb command, LocalStack creates the my-test-bucket bucket in its emulated environment. The successful creation is confirmed by the output: make_bucket: my-test-bucket.
  • When you list the buckets with aws s3 ls, it shows the newly created bucket as my-test-bucket, confirming the operation was successful.
  1. Why the localhost:4566 Page Remains Empty:
  • localhost:4566 is not intended to serve a graphical user interface (GUI) like the AWS Management Console. Instead, it acts as an endpoint for API requests from tools like the AWS CLI or SDKs.
  • LocalStack emulates AWS services by providing HTTP-based API endpoints. These APIs handle requests and respond accordingly, but LocalStack does not serve a web-based dashboard. Therefore, accessing localhost:4566 via a browser will result in a blank or empty page, which is completely normal.
  • To interact with LocalStack, users should rely on the AWS CLI, SDKs, or other infrastructure management tools (like Terraform). These tools send API calls to LocalStack, which then processes and responds with the requested information or performs actions such as creating S3 buckets.
  1. Why the S3 Bucket Is Created:
  • The aws s3 mb command in LocalStack simulates the creation of an S3 bucket, just as it would in AWS. In your case, the bucket my-test-bucket was created locally within LocalStack.
  • Even though LocalStack is emulating AWS S3 locally, the functionality is designed to be very similar to the actual AWS S3 service. Therefore, the aws s3 ls command shows the bucket because LocalStack has processed the request successfully and maintains an internal record of the bucket.
  1. Key Takeaways:
    • LocalStack is functional: The successful creation and listing of the my-test-bucket confirm that LocalStack is operating correctly and the AWS CLI is interacting with it as expected.
    • No graphical interface is provided at localhost:4566: LocalStack is designed to work through API calls, not through a web dashboard.
    • Use CLI for interaction: For operations like creating buckets, listing them, or interacting with other AWS services, the AWS CLI or other tools should be used to send requests to LocalStack's API endpoints.

Step 3: Steps to Store and Access Images & CSV in S3 (LocalStack)

1. Upload Files to S3 Bucket

Navigate to the directory where your images and CSV file are located:

cd "C:\Users\rawat\Documents\8 SEMESTER\
Cloud Computing\Lab\Experiment 3\Items"
Enter fullscreen mode Exit fullscreen mode

Run the following command to upload all files to the S3 bucket:

aws --endpoint-url=http://localhost:4566 --region
us-east-1 s3 cp . s3://my-test-bucket/ --recursive
Enter fullscreen mode Exit fullscreen mode
  • Purpose: This uploads all files (images & CSV) from your local directory to my-test-bucket.
  • Output: Each file's upload confirmation.

2. List Files in S3 Bucket

To confirm that the files were uploaded successfully, list them:

aws --endpoint-url=http://localhost:4566 --region
us-east-1 s3 ls s3://my-test-bucket/
Enter fullscreen mode Exit fullscreen mode
  • Expected Output:
  2025-02-18 10:30:00   12345 image1.jpg
  2025-02-18 10:30:01   67890 image2.png
  2025-02-18 10:30:02   45678 data.csv
Enter fullscreen mode Exit fullscreen mode

3. Access & Download Files

  • Download CSV File:
  aws --endpoint-url=http://localhost:4566 --region
  us-east-1 s3 cp s3://my-test-bucket/data.csv .
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Retrieves data.csv from S3 to your local machine.
  • Output: download: s3://my-test-bucket/data.csv to ./data.csv

    • Download Images:
  aws --endpoint-url=http://localhost:4566 --region us-east-1
  s3 cp s3://my-test-bucket/image1.jpg .
  aws --endpoint-url=http://localhost:4566 --region
  us-east-1 s3 cp s3://my-test-bucket/image2.png .
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Downloads the images locally for viewing.

Download Directly to a Specific Path

To download the file directly to C:\Users\rawat\Downloads\, use the following command:

aws --endpoint-url=http://localhost:4566 --region us-east-1 s3
cp s3://my-test-bucket/Sample_Housing_CSV_File.csv
"C:\Users\rawat\Downloads\Sample_Housing_CSV_File.csv"
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • aws s3 cp β†’ Copies the file from S3 to your local machine.
  • s3://my-test-bucket/Sample_Housing_CSV_File.csv β†’ Specifies the file location in the S3 bucket.
  • C:\Users\rawat\Downloads\Sample_Housing_CSV_File.csv β†’ Specifies the target directory for the downloaded file.

Verify Download

After running the command, check your Downloads folder. To confirm in Command Prompt, run:

dir "C:\Users\rawat\Downloads\Sample_Housing_CSV_File.csv"
Enter fullscreen mode Exit fullscreen mode

4. Print CSV Content in Command Line

After downloading the CSV, print its content using:

type data.csv
Enter fullscreen mode Exit fullscreen mode

OR (For Linux/macOS):

cat data.csv
Enter fullscreen mode Exit fullscreen mode
  • Expected Output (Example):
  Name, Age, City
  Alice, 25, New Delhi
  Bob, 30, Mumbai
Enter fullscreen mode Exit fullscreen mode

5. Open Images for Viewing

For Windows:

start image1.jpg
start image2.png
Enter fullscreen mode Exit fullscreen mode

For macOS:

open image1.jpg
open image2.png
Enter fullscreen mode Exit fullscreen mode

For Linux (if you have an image viewer installed):

xdg-open image1.jpg
xdg-open image2.png
Enter fullscreen mode Exit fullscreen mode

Useful Resources for Amazon S3

  1. AWS S3 Documentation

    Official AWS guide covering S3 concepts, APIs, and best practices.

  2. AWS S3 CLI Reference

    Detailed command-line instructions for managing S3 buckets and objects.

  3. LocalStack – AWS Services on Local Machine


    Learn how to simulate AWS S3 locally using LocalStack.

  4. The Life Cycle of an S3 Object – A Simple Tale of Data’s Journey


    A wonderful article explaining the S3 object lifecycle in a storytelling format. Written by @robot254 Thanks for this great piece!

  5. Learning AWS S3 on Localhost – Best Practices with Boto3 and LocalStack

    An insightful guide on working with AWS S3 locally using Boto3 and LocalStack. The visuals I’ve used in this guide are taken from this article β€” thanks @r0mymendez for this helpful resource! πŸ™Œ

πŸ“„ Want to see the output step by step? Check it out here:

πŸ”— Experiment 3 Output (PDF)

🧠 Want to see the input and output for each command in the Command Prompt along with a clear explanation? Check it out here:

πŸ–₯️ Command Prompt Input & Output Explanation (PDF)

πŸŽ‰ And that’s a wrap! Congrats and kudosβ€”you made it through! πŸŽ–οΈ

You have now understood the basics of cloud storage and AWS.

πŸ’‘ I hope this guide helped you! If you ran into any challenges, feel free to drop a commentβ€”we’ll debug and troubleshoot together! πŸ•΅οΈβ€β™‚οΈ

πŸ”₯ Stay tuned for the next article!

I'll walk you through Setting Up and Configuring Cloud Networking. β˜οΈπŸ›œ

πŸ’¬ Did you like this guide?

Drop a comment if it helped, share any useful S3 resources you love, or even a cool visual or diagram if you have one!

Let’s keep exploring the cloud together! πŸ’›πŸŒŸ

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (4)

Collapse
 
uzondu9 profile image
Uzondu β€’ β€’ Edited

AI and Cloud Services is such a booming field, and it's really important for people to take the time to analyze and understand its impact. I really enjoy seeing posts like this β€” even though I’m not planning to venture into it myself right now, it’s always insightful to read! 😊

Collapse
 
madhurima_rawat profile image
Madhurima Rawat β€’

Great to hear! πŸ˜„ I too read a lot of posts even if I may or may not venture into it at the moment β€” it’s always good to explore πŸ”. And whenever you decide to try it out, feel free to reach out if you hit any bumps! πŸ’‘πŸ’¬

Collapse
 
r0mymendez profile image
Romina Mendez β€’

Thank you for sharing part of my post :)

Collapse
 
madhurima_rawat profile image
Madhurima Rawat β€’

You're welcome!! πŸ˜„ Big fan of your blogs ❀️✨

Jetbrains Survey

Take part in the Developer Ecosystem Survey!

Share your thoughts and get the chance to win a MacBook Pro, an iPhone 16 Pro, or other exciting prizes. Help shape the coding landscape and earn rewards for your contributions!

Take the survey