Member-only story
Using moto from Rust to mock AWS calls
Testing cloud-native applications can prove difficult, mostly due to their dependency on proprietary cloud services whose behaviour is difficult to replicate in a test environment. Since I have a background as a cloud developer using (mostly) Python, my main issue with building (but mostly testing) Rust applications on AWS was missing a mocking library like moto.
Fortunately, moto can be run as a local server, and the AWS SDK for Rust allows you to specify the endpoint URL for each service that you are using. You can, therefore, create a setup that allows you to test your code against moto.
Why?
The best place to test your cloud-native application is, of course, in the cloud. Even if AWS themselves provided a way to run their services locally, you would probably still experience different behaviour in production. The best practices for setting up your AWS environments even suggest a sandbox account for each developer, where they can test and experiment. Additionally, AWS already provides guidelines on how to mock AWS SDK calls. So why would you use services like moto or localstack?
Although the mocked services are, obviously, not 1:1 copies of the real services, they are close enough to be used for testing purposes. This allows you to cover the functionality of structs or functions that access AWS — something that would be overlooked if you are using a library like mockall.