Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am trying to publish to an SNS topic which will then notify a Lambda function, as well as an SQS queue. My Lambda function does get called, but the CloudWatch logs state that my "event" object is None. The boto3 docs states to use the kwarg MessageStructure='json' but that throws a ClientError.

Hopefully, I've supplied enough information.

Example Code:

import json

import boto3

message = {"foo": "bar"}

client = boto3.client('sns')

response = client.publish(

    TargetArn=arn,

    Message=json.dumps(message)

)

1 Answer

0 votes
by (44.4k points)
  • Add a default key to your message payload
  • Specify MessageStructure

Code snippet:

import json

import boto3

message = {"foo": "bar"}

client = boto3.client('sns')

response = client.publish(

    TargetArn=arn,

    Message=json.dumps({'default': json.dumps(message)}),

    MessageStructure='json'

)

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...