- Le plus récent
- Le plus de votes
- La plupart des commentaires
To receive subscription notification messages in Amazon Simple Queue Service (SQS), you need to create an SQS queue and then subscribe it to the SNS topic. Once you have done that, you can use the ReceiveMessage API function to retrieve the subscription notification messages from the SQS queue. For enumerate through the message in an SQS queue then you use a loop to repeately call the 'ReceiveMessage' API function until there are no more messages in the queue.
Here's an example of how to use the ReceiveMessage function in the AWS SDK for Python (Boto3):
import boto3
# Create an SQS client
sqs = boto3.client('sqs')
# Specify the URL of the SQS queue
queue_url = 'https://sqs.region.amazonaws.com/account-id/queue-name'
# Receive messages from the SQS queue in a loop
while True:
response = sqs.receive_message(
QueueUrl=queue_url,
MaxNumberOfMessages=10,
VisibilityTimeout=0,
WaitTimeSeconds=0
)
# Process the messages
if 'Messages' in response:
for message in response['Messages']:
print(message['Body'])
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=message['ReceiptHandle']
)
else:
print('No more messages in the queue')
break
The messages from the queue in the same format in which we are sending them to the queue. If we are sending encrypted messages then we would receive encrypted messages only. if the messages are base64 encoded then you can write a code at your end to receive the messages using the ReceiveMessage API call[1]. Once you have the messages, you can then decode the received message using base64 library in your code. You can refer the links[2][3] for Encoding and Decoding Base64 Strings.
[1]. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html [2]. https://www.geeksforgeeks.org/encoding-and-decoding-base64-strings-in-python/ [3]. https://stackoverflow.com/questions/3470546/python-base64-data-decode
I am also struggling on this point, unable to send notifications from SQS to SNS and then SNS to any subscriber
Contenus pertinents
- demandé il y a un an
- demandé il y a 17 jours
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans