skip to Main Content

I have an application like this – sns -> lambda – so my lambda python function is invoked every time there was a new message published in SNS.
The whole code works on AWS UI, but I want to write a test function, thus I need to publish message from SNS topic from my local machine that would trigger that lamba I will watch the log in cloudwatch.

I have searched a lot but could not find something that would help a beginner like me. I installed awscli, extension on VScode and insalled Docker. My local machine is a debian(10) pc. Did not find any option on VScode for SNS.
Any help is much appreciated.

2

Answers


  1. If you want to manually test the behavior of your setup, use AWS cli from terminal to publish test messages. See the examples on the bottom of the page: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sns/publish.html

    Login or Signup to reply.
  2. You could use the AWS SAM CLI to test your function locally against a mock SNS event rather than using a function subscribed to the actual SNS topic.

    Using the AWS SAM CLI you can generate a sample event with this command

    sam local generate-event sns
    

    You can then modify it, save it, and use it with the sam local invoke --event mockEvent.json. You should then be able to see how your code will behave and view logs for the function.

    AWS SAM CLI ‘generate-event’ docs:
    https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-generate-event.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search