Localstack in Docker on Windows

Of course you want to use Windows because Macs are rubbish and Linux is cool, but it won’t run Fortnite.

I’m not promising that everything works perfectly, but you can definitely get the SQS service up and running.

Make sure that you have Docker installed, I’m assuming that you have.

Create the following docker-compose.yaml in some directory:

version: "3.8"networks:
name: localstack-net
driver: bridge

image: localstack/localstack
privileged: true
- localstack-net
- "4566:4566"
- "4571:4571"
- DATA_DIR=/tmp/localstack/data
- ./.temp/localstack:/tmp/localstack

Now type:

docker-compose up -d

This might take a few minutes as it needs to pull all the resources down.

And, thats it! Yeah, really that was it.

OK, now you want to test this. I’m really sorry that I’ve not just ripped off some other guide that doesn’t work and I’ve actually spent some time figuring out how to get this working, but if you can excuse that then you might want to try this to prove to yourself that you have a working installation.

Navigate to http://localhost:4566/health, you should see it display

{"services": {"sqs": "running"}}

That is the sanity check, now you actually want to create a queue or something. So here is the fun bit because AWS lets you run the cli through Docker itself, honestly I don’t know why you would want to do this other than to prove to yourself just how cool you are, but there you are, that’s what we’re going to do.

Now in Macos (which is RUBBISH) or Linux (which is cool, but can’t run Fortnite) there is a really nice command called alias that lets you do something like:

alias laws='docker run --network localstack-net --rm -it amazon/aws-cli --endpoint-url=http://localstack:4566'

Whence you can run all of your commands through the alias laws. Unfortunately the Windows equivalent doskeys simply doesn’t work in PowerShell and PowerShell is cool now (because it has a black terminal with an off white correctly sized consolas font, not a rubbishy navy blue one with a just slightly too small not quite consolas font) and that makes doskeys useless and rubbish.

Here unfortunately some hoops need to be jumped through to get back to the laws awesomeness, but because Windows and PowerShell are cool, we can do it.

The trick here is to create a new PowerShell module that creates this alias for you, so make a file called send-aws-docker.psm1 and then paste the following code into it:

function Send-AwsDocker
docker run --network localstack-net --rm -it `
-v $env:userprofile\.aws\localstack:/root/.aws `
amazon/aws-cli `
--endpoint-url=http://localstack:4566 `
Set-Alias -Name laws -Value Send-AwsDocker

Now all you need to do is type:

Import-Module ./send-aws-docker.psm1

And you can use the use the laws alias as Rama intended.

First you need to configure aws to talk to localstack using the following settings:

laws configure
AWS Access Key ID [None]: test
AWS Secret Access Key [None]: test
Default region name [None]:
Default output format [None]: yaml

Then you can create a queue:

laws sqs create-queue --queue-name queue1
> QueueUrl: http://localhost:4566/000000000000/queue1

The first time you run this it will take some time as it needs to pull down the Docker image, but after that it is pretty quick.

And that is basically it.

One last thing you probably want to do is to get this module to auto-load out of your profile each time you open a new terminal, this is easy to do, but I really can’t be bothered to explain it here. At some point I might write it up because I’m now a total PowerShell fanboy and want everyone to love it as much as I do, but until then you are going to need to roll it yourself.