Use ElasticMQ to test AWS SQS using AWS SDK v2 in Golang

AWS SQS can be great low-friction service for developing applications that use a queue. But being a cloud-based managed service, how would you write isolated integration tests for it? Without either sharing a queue, or creating new queues in AWS each time, you can run ElasticMQ as an SQS-compatible queue and configure the AWS SDK to use that instead. There are less examples for version 2 (v2) of the AWS SDK, but the concept works similarly in Golang as with other programming languages.

The main different between the AWS SDK v1 and v2 is needing to use an endpoint resolver to force the SDK to talk to ElasticMQ, since it will not respect the endpoint provided as part of the queue URL anymore.

You can either create a new queue using the AWS SDK and use the returned queue URL to send and receive messages or you can configure ElasticMQ to create specific queues on startup

Add comment