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.

Prerequisites

  • Python (both Python 2.x and 3.x supported)
  • pip (python package manager)
  • Docker
  • AWS CLI (for interacting with LocalStack after installation)

Installing LocalStack

Running LocalStack

Creating our first S3 bucket with LocalStack

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:

We can create a bucket my-bucket by running aws s3api create-bucket --bucket my-bucket --endpoint-url http://localhost:4566.

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

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.

To confirm our object is now in the bucket, run aws s3api list-objects-v2 --bucket my-bucket --endpoint-url http://localhost:4566.

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.

Conclusion

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

  1. AWS CLI — Install

Image credit: REVOLT

Originally posted on my blog.

Senior Engineer @ Culture Amp. Tinkerer and professional self-isolator in 2020.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store