2 Answers
- Newest
- Most votes
- Most comments
5
To successfully push a message to Amazon SNS with MessageAttributes, you need to ensure that the MessageAttributes parameter is correctly structured as a dictionary. Each attribute must be a dictionary containing StringValue and DataType.
import boto3
# Create an SNS client
sns_client = boto3.client('sns')
# Define the message
message = 'This is a test message'
# Define the MessageAttributes
message_attributes = {
'S3_Bucket': {
'StringValue': 'test-s3',
'DataType': 'String'
}
}
# Publish the message to the SNS topic
response = sns_client.publish(
TopicArn='arn:aws:sns:region:account-id:topic-name',
Message=message,
MessageAttributes=message_attributes
)
print(response)
0
I tried as below and its working now, Thank you very much Thanniru Anil Kumar !
s3_bucket_name='test-s3' message_attributes = { 'S3_Bucket': { 'StringValue': s3_bucket_name, 'DataType': 'String' } }
answered 2 years ago
Relevant content
- asked 3 years ago
- asked 4 years ago
- AWS OFFICIALUpdated 3 years ago

Thank you very much Thanniru, It's awesome. It is working for the same that you shared.
But I am not getting any response when I pass the bucket name from a variables
s3_bucket_name="test-dummy" message_attributes = "{'S3_Bucket': {'StringValue':'" + s3_bucket_name+ "','DataType': 'String'}}"