Localstack – S3
Localstack provide the easy to run local cloud mock/testing framework. With the help of Localstack we can spin up the some of AWS services those are available free through localstack.
Let’s start work on the setup of AWS S3 service on the local environment step by step:
Step 1: First install the AWS cli on your local machine with the help of link: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
Step 2: Once you install the link just ensure that aws cli working on your machine or not with the help of below command:
aws --version
Step 3: Create the docker compose yaml file to define the localstack configuration:
version: "3.8"
services:
localstack-s3:
image: localstack/localstack:latest
container_name: localstack-aws
environment:
- SERVICES=s3
- EDGE_PORT=4566
- DEFAULT_REGION=us-west-2
- DATA_DIR=/tmp/localstack/data
ports:
- "4566-4583:4566-4583"
- "8055:8080"
volumes:
- './.localstack:/tmp/localstack'
- '/var/run/docker.sock:/var/run/docker.sock'
Step 4: Setup the AWS configure to set the access, secret key and default zone by setting the mock values.
aws configure
Step 5: Run the docker yaml file with the below command
docker compose up
Step 6: localstack container will be up and running on the port 4566, we can verify on the browser with the curl : http://localhost:4566/health
Step 7: Now we can run the AWS S3 service from the local with the below commands
aws --endpoint-url=http://localhost:4566 s3 ls
aws --endpoint-url=http://localhost:4566 s3 cp org s3://test/org --recursive
aws --endpoint-url=http://localhost:4566 s3 mb s3://test
I will share more commands soon (may be in other post 🙂 )on aws cli with interaction with S3 like list of files, list of bucket, file crud operation like create/delete/update/list.