Skip to content

Instantly share code, notes, and snippets.

@bookshelfdave
Created May 4, 2017 19:02
Show Gist options
  • Save bookshelfdave/7191e7f173139719f695e896c037f669 to your computer and use it in GitHub Desktop.
Save bookshelfdave/7191e7f173139719f695e896c037f669 to your computer and use it in GitHub Desktop.
sample Python code using SQS
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)
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'])
@ParthibanSoundram
Copy link

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.

@grove80904
Copy link

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