Simulating s3 bucket on localhost

israellopes

Israel-Lopes

Posted on May 10, 2023

Simulating s3 bucket on localhost

If you landed here by parachute and don't know how to configure LocalStack to simulate an AWS environment, follow this post: Simulating AWS CLI with LocalStack

What Bucket S3?

Bucket S3 (Amazon Simple Storage Service) and a cloud storage container. A good one
analogy we can do and that Bucket S3 would be a directory in a linux environment in which you
can create the boards that would be the bucket, and within the directors the data files that
You want to store. You don't need much attention to realize that the bucket commands are
similar to the commands of listing and deleting on Linux.

Now we follow the tutorial.

Here we will learn:

  • Create Bucket
  • climb files to the bucket
  • List Buckets and Files
  • Delete Bucket files

To facilitate learning and is similar to the service of Amazon, let's create an alias.

Inside I give your .Bashrc or another preferably, paste the follownet code.



source /home/oem/Workspace/myenv/venv/bin/activate
alias aws="aws --endpoint-url=http://localhost:4566"


Enter fullscreen mode Exit fullscreen mode

Do not forget to load the file: source ~/.BASHRC

In this way we are overcrowding the AWS command to that of Locastack. Now in the
do:

aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket-to-test

Now it will be that way: AWS S3 MB S3: // My-Bucket-to-Test, so we can create our Bucket S3.

If you want, you can subscit the name "My-Bucket-To-Test" for the bucket name you want.

When creating Bucket he had returned the message "Make_Bucket: My-Bucket-To-Test" on the prompt output.
Here we will exemplify some ways to climb files to Bucket S3.

Bucket Upload

Now let's are in the bucket data mass, so it will climb all files that
are within the specified directory.

aws s3 sync /home/oem/Workspace/local-stack-aws/bucket-s3/ s3://my-bucket-to-test/

When uploading to Bucket, the file will be stored with the same board structure. my
It was as follows:

aws s3 sync /home/oem/Workspace/local-stack-aws/bucket-s3/product_data.json s3://my-bucket-to-test/

If you want to climb only one file, we can do it like this:

aws s3 cp /home/oem/Workspace/local-stack-aws/bucket-s3/product_data.json s3://my-bucket-to-test/

Now that we go up it let's go Baixalo:

Bucket download

aws s3 cp s3://my-bucket-to-test/product_data.json - | cat

This command assigns the Product_Data file and Cat on its exit, returning the object.

deleting bucket file

First let's list our bucket:

aws s3 ls s3://my-bucket-to-test/

Now that we already know which one delete, let's go on:

aws s3 rm s3://my-bucket-to-test/product_data.json

Upon running the command it returns the following message:

delete: s3://my-bucket-to-test/product_data.json

We just said that we want to delete the Product_Data.json file of our Bucket. If we list the
Content of our Bucket again, we will see that it no longer exists.

Texto alternativo da imagem

💖 💪 🙅 🚩
israellopes
Israel-Lopes

Posted on May 10, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related