Skip to content
Advertisement

How to send a message to local SQS queue using python boto3?

I’m trying to emulate AWS SQS functionality using https://github.com/roribio/alpine-sqs container.

I was able to run the docker container and send the messages to the queue using terminal. configured AWS Access Key ID and AWS Secret Access Key to empty strings using aws configure

The command I used to send the message to the SQS queue container is this

aws --endpoint-url http://localhost:9324 sqs send-message --queue-url http://localhost:9324/queue/default --message-body "Hello, queue!"

I was able to receive the message and I can see it in the dashboad in browser at localhost:9235.

But when I try to send the message using boto3 in python, it is throwing an error.

Traceback (most recent call last): File “/home/infomagnus/PycharmProjects/InfoMagnus/workload/app/workload/services/queue_services.py”, line 13, in ‘Information about current NY Times fiction bestseller for ‘ File “/home/infomagnus/envs/DSDPenv/lib/python3.7/site-packages/botocore/client.py”, line 357, in _api_call return self._make_api_call(operation_name, kwargs) File “/home/infomagnus/envs/DSDPenv/lib/python3.7/site-packages/botocore/client.py”, line 661, in _make_api_call raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the SendMessage operation: The security token included in the request is invalid

Not sure why I’m getting the error even after setting the keys using aws configure.

Everything that I’m running is in my local.

Here’s my code:

import boto3
sqs = boto3.client('sqs', aws_access_key_id=None, aws_secret_access_key=None)
queue_url = 'http://localhost:9324/queue/default'
resp = sqs.send_message(
    QueueUrl=queue_url,
    MessageBody=(
        'Sample message for Queue.'
    )
)
print(resp['MessageId'])

Advertisement

Answer

You forgot to pass endpoint_url.

sqs = boto3.client('sqs', aws_access_key_id=None, aws_secret_access_key=None, endpoint_url='http://localhost:9324')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement