[{"data":1,"prerenderedAt":71},["ShallowReactive",2],{"pattern-sns-lambda":3},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":13,"deploy":15,"description":20,"extension":21,"framework":22,"gitHub":23,"highlight":6,"introBox":32,"language":37,"level":38,"meta":39,"patternArch":40,"resources":53,"s3URL":6,"services":62,"stem":63,"testing":64,"videoId":28,"__hash__":70},"patterns\u002Fpatterns\u002Fsns-lambda.json","Amazon SNS to AWS Lambda",null,{"headline":8,"text":9,"test":12},"Cleanup",[10,11],"1. Delete the stack: \u003Ccode>sam delete --stack-name STACK_NAME\u003C\u002Fcode>.","2. Confirm the stack has been deleted: \u003Ccode>aws cloudformation list-stacks --query \"StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus\"\u003C\u002Fcode>",[],[14],"content\u002Fcontributors\u002Fjames-beswick.json",{"text":16,"command":19},[17,18],"sam build","sam deploy --guided",[17,18],"Create a Lambda function that subscribes to an SNS topic","json","AWS SAM",{"template":24,"payloads":30},{"projectFolder":25,"repoURL":26,"templateURL":27,"readmeURL":28,"templateFile":29},"sns-lambda","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Fsns-lambda","serverless-patterns\u002Fsns-lambda","","template.yaml",[31],{"headline":28,"payloadURL":28},{"headline":33,"text":34,"text2":28},"How it works",[35,36],"The SAM template deploys a Lambda function, an SNS topic and the IAM permissions required to run the application. SNS invokes the Lambda function when new messages are available.","When messages are sent to the SNS topic, they are delivered as a JSON event payload to the Lambda function.","Node.js","100",{},{"icon1":41,"icon2":46,"line1":50},{"x":42,"y":43,"service":44,"label":45},20,50,"sns","SNS",{"x":47,"y":43,"service":48,"label":49},80,"lambda","AWS Lambda",{"from":51,"to":52,"label":28},"icon1","icon2",{"headline":54,"bullets":55},"Additional resources",[56,59],{"text":57,"link":58},"Choosing between messaging services for serverless applications.","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fchoosing-between-messaging-services-for-serverless-applications\u002F",{"text":60,"link":61},"Using AWS Lambda with Amazon SNS","https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fwith-sns.html",{"from":44,"to":48},"patterns\u002Fsns-lambda",{"headline":65,"text":66},"Testing",[67,68,69],"Use the AWS CLI to send a message to the SNS topic and observe the event delivered to the Lambda function:","1. Send the SNS message: \u003Ccode>aws sns publish --topic-arn ENTER_SNS_TOPIC_ARN FROM_OUTPUT --subject testSubject --message testMessage\u003C\u002Fcode>.","2. Retrieve the logs from the Lambda function: \u003Ccode>sam logs -n ENTER_YOUR_CONSUMER_FUNCTION_NAME\u003C\u002Fcode>.","JKfMFMWTccC1ZhnmWBpXBHa6hj0AP7rOmkflDES2YUQ",1778846888118]