Invoking the Lambda function via AWS Console or AWS CLI to subscribe or publish a message to the Simple Notification Service to send an email.
NOTE: Update the email subscription endpoint in the lambda-sns-stack.ts
file inside the lib/stacks
folder.
- Go to Lambda → Lambda Function → Test tab
- Update the Event JSON textarea field (see sample payload)
- Click on the Test button in the upper right corner
-
Use the following command and replace the placeholder
lambda_function_name
with the actual Lambda function nameaws lambda invoke \ --function-name lambda_function_name \ --payload '{"action": "subscribe", "content": { "user": { "name": "John Doe", "email": "[email protected]" }}}' \ --cli-binary-format raw-in-base64-out \ response.json
-
Subscribing to the SNS Topic
{ "action": "subscribe", "content": { "user": { "name": "John Doe", "email": "[email protected]" } } }
-
Publishing a message to the SNS Topic
{ "action": "alert", "content": { "application": "ABC Solutions & Services", "message": "{\"log_code\":\"SQSError\",\"log_msg\":\"FailedeventfromAmazonSQS\",\"log_level\":\"ERROR\",\"log_keys\":{\"eventSource\":\"aws:sqs\",\"messageId\":\"9ab59c5d-4650-4e4f-abcd-bff95a6a4996\",\"order\":{\"referenceId\":\"SMPLORDR-1234567890\",\"status\":\"RECEIVED\",\"item\":[{\"id\":\"SMPLITM-12345\",\"name\":\"SampleItem\",\"price\":1234.5}],\"quantity\":1,\"timestmap\":\"2023-04-2602:32:59\"}},\"log_timestamp\":\"2023-04-2602:33:00\"}" } }
- Publish
- Subscribe
- Amazon SNS FAQs
- Email notifications
- Amazon Simple Notification Service endpoints and quotas
- Tutorial: Using AWS Lambda with Amazon Simple Notification Service
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
-
Install all the dependencies, bootstrap your project, and synthesized CloudFormation template.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/lambda/lambda-sns$ make init # With "profile" parameter dev@dev:~:aws-cdk-samples/lambda/lambda-sns$ make init profile=[profile_name]
-
Deploy the project.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/lambda/lambda-sns$ make deploy # With "profile" parameter dev@dev:~:aws-cdk-samples/lambda/lambda-sns$ make deploy profile=[profile_name]