A few months back I got into a conversation with a friend about how to manually “play” with an AWS application while developing a feature. His way of doing it is to push to Github repo any feature he wants to play with, spin up an EC2 instance, wire it up with all other needed infrastructure, and go on and do whatever he planned to do with it.

After hearing it, I inquired: “Why not play with your half baked — half bugged feature locally? with test data, and mock AWS dependencies?”.

We can sum his answer with “it seems easier my way”. While at it I should mention that we’re both “simple” backend engineers, and building a development environment indeed seemed like a hustle.

I’m not too good with infrastructures too, but last week I really needed a dev env to test all moving parts of my clickstream AWS hosted application.

This is the story of how I went from Zero to fully functional AWS local environment in just 2 days. I hope that within a few minutes of reading, I’ll be able to convince you it’s easy enough, and you can do it yourself.

First let’s answer the unavoidable question: Why? why is testing in the cloud is not good enough?

In most cases debugging is easier locally.

It takes time, getting your code there, and spinning up an instance will forever be slower than just firing up a few commands locally.

It’s not free! spinning up instances has a cost.

You need to be online to do that, what if you’re working on the train? or while flying? (I’m a bit afraid that until this piece gets published high-speed internet will become a basic necessity on commercial flights)

Now imagine building an AWS local version by your own! it’s a huge project, just building the smallest mock for the simplest usage of SQS, for example, sounds like an enormous effort.

Fortunately enough, the good people of localstack did that for us, and created a local, offline version of the AWS infrastructure! With localstack, you easily can spin app a fully functional cloud locally.

The magic comes with a cost though. dependencies!

And quite a few of them: python, pip, npm and more. it’s not a deal breaker list of dependencies since you probably already have most of them, but still, wouldn’t it be nicer not to need them? furthermore how awesome would it be if a new onboarding team member wouldn’t need to deal with them at all? consider someone with less experience or someone from a different eco-system experience (like the year-ago me).

Introducing docker, docker images, and docker-compose

With Docker, you can easily get a fully working localstack, beautifully bundled in a docker image. if you’ll just run docker pull localstack/localstack and then docker run localstack/localstack , you’ll have a running a localstack while having only a single dependency — Docker.

docker run localstack

Now that we have a running AWS, you’ll probably want to use it: Create Dynamo tables, SQS queues, Kinesis streams, etc…we can use aws-cli, but again, aws-cli comes with more dependencies.

There’s a docker to solve those too: aws-cli docker!

I’ve promised it’ll be simple, so here comes docker-compose.

Docker compose is a tool that can be used to easily get multiple dockers up and running, and making them all work together miraculously!

All you need to know is to write short descriptive YML file and the two magic commands:

docker-compose up for spinning your local env up

for spinning your local env up docker-compose down for tearing it down

I used it to implement the following process:

get a localstack docker up and running for my local env with Kinesis, Dynamo, and a configured network. using aws-cli docker I’ve executed my setup: I’ve created tables and streams and even populated it with initial data.

All of that came with the cost of only 2 dependencies: (docker, and docker-compose) while writing less than 100 lines of code.

The biggest benefit though came from sharing my magic solution for local env with my teammates. after investing my 2 days of configuration and development, the rest of the team got a working devenv for free, without installing any dependencies (all of them already had Docker), and without configuring anything.

Now a future new teammate will get a fully functional environment absolutely for free.

I think now it’s time to come clean. I ’ve lied a bit earlier, I did not make that from absolutely Zero, I had a small head start — a template created by a co-worker for a different project, so you’ll have the same “head start” from me! this is my docker-compose.yml :

I’m sure this can be made better! I’m no expert, and this was one of my first actual encounters with writing anything Docker-related. but this shows you how simple that is!

One final small suggestion: a similar solution can be applied with Redis, and redis-cli, other DBs and datastores, and many many additional useful applications and tools for your local environment.

By the way, executing docker-compose up with given yml file will result in the following output:

And you can go to http://0.0.0.0:8080 and see admin page for your localstack to make sure everything is up and running:

Your thoughts and comments are always welcome! come find me on Twiter: https://twitter.com/BorisCherkasky