Search code examples
pythonamazon-sqsboto3elastic-mq

Set the endpoint for boto3 SQS


Our application uses amazon's SQS for message queues and we use elasticMQ for testing/staging; elasticMQ is a message queue server that is fully compatible with SQS. Since the majority of our application is in java, we can run embedded elasticMQ in our tests or staging, switch over our queue endpoints to point to elasticMQ and voila, everything works very nicely and we don't touch our production queues.

That being said, we have some of our application written in python - which uses boto3 for SQS requests. Since elasticMQ can also be run as a standalone application I was wondering if it was possible to switch the endpoint from the default url (sqs.region.amazonaws.com:80) to something else (localhost:9324) in boto3. I've scoured the documentation and SO but haven't been able to identify if what I'd like to do is even possible.


Solution

  • You can pass in the endpoint_url to the client / resource constructor.

    import boto3
    
    sqs = boto3.resource('sqs')
    emq = boto3.resource('sqs', endpoint_url="http://www.foo.com")
    

    docs