Reputation: 1702
I created a Lambda function that will publish a message to a slack channel and I have it triggered by an SNS topic. Can I use the SNS subscription filter policy to pass data to my Lambda function so it can be read and used in the Lambda function? I assume Lambda could read the parameters passed from SNS in the Lambda with using event?
event['message']
I just don't want to create a Lambda function for each trigger I will create. I want to have one Lambda function, pass in the custom text from separate SNS topics therefore making the function reusable.
I have one SNS topic for CodeDeploy passing and one for it failing. I want to just pass in the message "CodeDeploy passed" or "CodeDepoy failed" into the Lambda function.
Thanks for any help or advice!!
Upvotes: 2
Views: 1345
Reputation: 7407
You should trigger your Lambda function with CloudWatch Events with Event Patterns. This way you can specify the event that your Lambda function will receive (constant or parts of the source event).
Here is an example for a 'SUCCESS' with CodeDeploy:
You can achieve what you want using a single rule matching both 'SUCCESS' and 'FAILURE' and a logic in your Lambda function based on the source event or part of it to create a Slack message.
Upvotes: 2