Nirupama Rachuri
Nirupama Rachuri

Reputation: 113

AWS SQS boto3 send_message returns 'dict' object has no attribute 'send_message'

Upvotes: 4

Views: 17338

Answers (1)

mootmoot
mootmoot

Reputation: 13176

I think you mix up the boto3 client send_mesasge Boto3 client send_message with the boto3.resource.sqs ability.

First, for boto3.client.sqs.send_message, you need to specify QueueUrl. Secondly, the the error message appear because you write incorrect print statement.

# print() function think anything follow by the "queue" are some dictionary attributes  
print queue responses = queue.send_message(MessageBody='Test')

In addition, I don't need to use boto3.session unless I need to explicitly define alternate profile or access other than setup inside aws credential files.

import boto3 
sqs = boto3.client('sqs') 
queue = sqs.get_queue_url(QueueName='queue_name')
# get_queue_url will return a dict e.g.
# {'QueueUrl':'......'}
# You cannot mix dict and string in print. Use the handy string formatter
# will fix the problem   
print "Queue info : {}".format(queue)

responses = sqs.send_message(QueueUrl= queue['QueueUrl'], MessageBody='Test')
# send_message() response will return dictionary  
print "Message send response : {} ".format(response) 

Upvotes: 5

Related Questions