1 Answer
- Newest
- Most votes
- Most comments
0
Hello.
Please use "receive_message()" to retrieve messages from the SQS queue.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/receive_message.html#
Also, even if you display the message with "receive_message()", it will remain in the SQS queue, so if you successfully retrieve the message, please delete it with "delete_message()".
If you don't delete the message, the same message will be processed over and over again.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/delete_message.html
The code below is a sample that retrieves messages from an SQS queue called test in the Tokyo region.
import boto3
import json
import time
sqs = boto3.client('sqs', region_name='ap-northeast-1')
queue_url = 'https://sqs.ap-northeast-1.amazonaws.com/1111111111/test'
while True:
response = sqs.receive_message(
QueueUrl=queue_url,
AttributeNames=[
'All'
],
)
if 'Messages' in response:
sqs_message = json.loads(response['Messages'][0]['Body'])
print(sqs_message)
message_del = sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=response['Messages'][0]['ReceiptHandle']
)
time.sleep(60)
else:
print ('No Messages')
break
Relevant content
- asked a year ago
- asked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 8 months ago