LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications. In today’s post, we’re going to have a quick look at setting up LocalStack locally to work with their free tier AWS emulated products.
In particular, today’s post will have a quick look at emulating S3 buckets for local development.
Before getting started, it is required that you have the following on your machine:
- Python (both Python 2.x and 3.x supported)
- pip (python package manager)
- AWS CLI (for interacting with LocalStack after installation)
Following the instructions on their README, we can use
pip to install the package.
Once installed, we can get everything up by running
localstack start. You will get feedback in the terminal that a number of services are started and finally get the service list with the ports they are running on. By default, these services will start on port 4566. Easy peasy!
Creating our first S3 bucket with LocalStack
Now that things are running, we can run some basic tests using the AWS CLI. I am not going to go into the installation process for the CLI, so follow the link above and use those installation instructions if you have not yet installed the CLI.
We will use the
aws s3api [command] --endpoint-url http://localhost:4566 pattern to interact and use the local endpoint to list and create buckets.
To show what we currently have, we can run
aws s3api list-buckets --endpoint-url http://localhost:4566 and we will get something like the following:
To confirm it has been made, we can run
aws s3api list-buckets --endpoint-url http://localhost:4566 once again:
Adding and removing objects locally
Create a new
temp.txt and add some content. In my case, I added
Once this is done, we can put the file
temp.txt into bucket
my-bucket by running
aws s3api put-object --bucket my-bucket --key temp.txt --body temp.txt --endpoint-url http://localhost:4566. You will have an object returned with an
ETag value if successful.
Now that we have proven how to develop and test the S3 service locally, we can terminate our
localstack instance in the terminal to tear down the local infrastructure.
In summary, we installed LocalStack to our local machine and explored one of the free-tier services in S3.
I am working locally with interacting with some AWS services through some language APIs, and the capability to do so locally with LocalStack has been a real time-saver for putting together some infrastructure solutions for my personal projects.
I highly recommend giving it a go for your own infrastructure development. There may be some issues that I am yet to run into, but as far as a lightweight approach to quickly interacting with files locally and not expending costs, it has been great for introductions into some of the AWS products.
Resources and further reading
Image credit: REVOLT
Originally posted on my blog.