Created
May 4, 2017 19:02
-
-
Save bookshelfdave/7191e7f173139719f695e896c037f669 to your computer and use it in GitHub Desktop.
sample Python code using SQS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
sqs = boto3.client('sqs', region_name="us-west-2", | |
aws_access_key_id='', | |
aws_secret_access_key='' | |
) | |
queue_url = '' | |
response = sqs.receive_message( | |
QueueUrl=queue_url, | |
AttributeNames=[ | |
'SentTimestamp' | |
], | |
MaxNumberOfMessages=1, | |
MessageAttributeNames=[ | |
'All' | |
], | |
VisibilityTimeout=0, | |
WaitTimeSeconds=0 | |
) | |
message = response['Messages'][0] | |
receipt_handle = message['ReceiptHandle'] | |
sqs.delete_message( | |
QueueUrl=queue_url, | |
ReceiptHandle=receipt_handle | |
) | |
print('Received and deleted message: %s' % message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
sqs = boto3.client('sqs', region_name="us-west-2", | |
aws_access_key_id='', | |
aws_secret_access_key='' | |
) | |
queue_url = '' | |
response = sqs.send_message( | |
QueueUrl=queue_url, | |
DelaySeconds=10, | |
MessageAttributes={ | |
'Title': { | |
'DataType': 'String', | |
'StringValue': 'The Whistler' | |
}, | |
'Author': { | |
'DataType': 'String', | |
'StringValue': 'John Grisham' | |
}, | |
'WeeksOn': { | |
'DataType': 'Number', | |
'StringValue': '6' | |
} | |
}, | |
MessageBody=( | |
'Information about current NY Times fiction bestseller for ' | |
'week of 12/11/2016.' | |
) | |
) | |
print(response['MessageId']) |
I think the issue is with the MessageBody statement. You have 2 separate strings without a comma separator. Either combine the 2 strings into 1 longer string or try adding a comma between the 2 strings.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying this but it shows error
Traceback (most recent call last):
File "sqs.py", line 42, in
lambda_handler()
File "sqs.py", line 33, in lambda_handler
'Information about current NY Times fiction bestseller for '
File "/usr/local/lib/python3.6/dist-packages/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.6/dist-packages/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MissingParameter) when calling the SendMessage operation: The request must contain the parameter MessageGroupId.