LocalStack: local AWS mocking
As part of my ‘final work’ for university I had to look into mocking AWS locally… I quickly stumbled upon some tools and I was relieved that I did not have to make them from scratch. Why recreate something that already works and is open to edit and if I were to find some bugs I could fork it, fix the bugs and create a PR on the main repository so everyone could benefit from this — yay open source.
While digging into AWS mocking I have found that a lot of those tools use Python, it is not my most favourite language but it is a powerful one and easy to create scripts with. So upon my adventures in the web…
Moto
Moto is a library that allows your tests to easily mock out AWS Services. https://github.com/spulec/moto
Moto seems to be the way to go for the Pythonic way… And I was very suprised by the given functionalities of it. So what can it do? A lot… And with a lot I certainly mean a lot! From mocking S3 buckets, DynamoDB (mocked databases?!), Lambdas (‘serverless functions’), Simple Email Service (SES) and much much more.
I was thinking, hell yeah I can anything now! But then I realised that this must be too good to be true and upon looking a bit deeper yes… Not everything works 100% but still it is still pretty impresive and it could be a good base for my applications! The full list of moto’s coverage can be found here (warning: it is a big list): https://github.com/spulec/moto/blob/master/IMPLEMENTATION_COVERAGE.md
Now that we have something to mock AWS with we should try it out, spin up a S3 bucket and upload some of our favourite cat pictures! But wait… my Google adventures did not end yet! Let me introduce you to LocalStack…
LocalStack
LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications.
Currently, the focus is primarily on supporting the AWS cloud stack. https://github.com/localstack/localstack
So what is LocalStack…? Don’t we have Moto already? Is this better?
To answer all those questions with one answer… LocalStack is a wrapper around Moto as in it actualyl uses Moto but it already did most of the setup parts so we do not have to do it again, pretty neat isn’t it?
They offer both a free tier and paid tier (their pro version). The free tier gives you a lot of services to work with some basic integrations — it’s not ideal to use something with a lot of locked features but for the most part I see them as additions and the core components are available for free. And if suddenly most free tier services become paid we can switch over to Moto.
Note: the UI/dashboard is very lacking of LocalStack but personally I do not need this, I am fine with using the AWS CLI, https://aws.amazon.com/cli/, tools (yes, they do work! Just set your endpoint to localhost:* where * is your port)
Next up I will address using LocalStack with Docker! I am still in the progress of writing the post as there are some (known) bugs that I am trying to combat regarding file permissions in the /tmp folder in the Docker container. Big spoiler: we will upload a cat picture to a locally mocked S3 bucket 😮
Hi there, this is a small footnote, I am trying to branch out with my blogging and I will be posting on both Medium and Steemit. This is mainly to collect as much feedback as I can so I can potentially improve.
Congratulations @thelonelydev! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!