Using API Gateway to publish SNS topics / multiple lambda function with API Gateway
Right now my requirement is, whenever I get data through API, I have to save it into 2-3 different places (for example, into my own DB, into some BI service and also sometimes into a logging DB).
I don’t know if it’s possible to bind a single resource and single method into multiple lambda functions or so. So, my alternate approach was, as I already know how to trigger multiple lambda functions by subscribing to SNS topic, I thought maybe if I can somehow publish to SNS topic from the API Gateway, the rest will be easy. My current thinking is something below:
But the problem is, I am not able to publish to SNS topic from the API Gateway. I am getting errors like
My approach is, create a normal SNS topic. Then, create a special role policy like below:
Then creating a API with POST/GET method (I tried both) and added SNS topic as AWS Service Proxy and the Role as Execution role.
You have to pass in TopicArn or TargetArn to SNS via AWS API Gateway. There are the different ways can archive that.
Here is the step by step instruction provided by AWS API Gateway.