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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.