When using a LocalStack container with Testcontainers, is there a way to purge all state, no matter what it is? That means, delete all SQS queues and their contents, all SNS topics, and everything else that LocalStack may store.
Use case
LocalStack is used for integration tests. The container is started by the test case via Testcontainers. There are many integration tests using LocalStack now, and each starts their own LocalStack instance. This is necessary in order to isolate test cases from one another; remaining messages from a previous test case must not influence the results from another test case.
As the number of those integration test cases has grown, LocalStack startup time has become an issue. I am looking for a way to reuse the same LocalStack instance for all integration tests without putting any restrictions on the way the integration tests are written.
As a workaround, I am considering to generate a unique prefix for all SQS queues and SNS topics, which will be prepended to the respective queue/topic names. This prefix should be unique per test case.
However, this is slightly unclean, as the messages would still be lingering on the LocalStack instance, even when the test case is done. It would be better to create a truly "clean slate" state after each test case completes.
In my case, tests are implemented using Scala, and the Testcontainers-Scala library is used. However, any JVM-based solution should work, such as a Java-based solution.
What I have considered
So far, I found the documentation and the API confusing, which probably reflects my lack of deep knowledge about LocalStack.
I guess it would be possible to "purge" a whole LocalStack instance by using the CLI command and some trickery. However, this would involve calling a Bash script from the running integration tests within the JVM, which doesn't sound like a good idea. It would not be portable (easily) to Windows machines. It would be much more useful if all of this could be done directly from the JVM, for example by interacting with the running LocalStack container via HTTP.
I focused my question on SQS and SNS because this is the current use case. In the future, as the project evolves, other services may be added. But those may be seen as separate cases.
As for SQS and SNS, a solution would have to:
- Either be able to delete all queues/topics at once with a single command,
- Or be able to list all queues/topcis that exist, and then delete each of them individually.