This is a simple Lambda with REST API and SNS enabled. Firstly, have a look the Nodejs script:
AWS SAM template yaml file:
Generate AWS CloudFormation yaml file and package / zip / create an artefact (need to create AWS S3 bucket hello-world-tub in advance):
1 2 3 4 5 6
𝜆 sam package --profile personal --template-file template.yml --output-template-file cloudFormation.yml --s3-bucket hello-sam-tub Uploading to 7431f83ac979bfccc26980049807e595 1461 / 1461.0 (100.00%)
Successfully packaged artifacts and wrote output template to file cloudFormation.yml. Execute the following command to deploy the packaged template sam deploy --template-file /Users/terrence/Projects/hello-sam/cloudFormation.yml --stack-name <YOUR STACK NAME>
Can also create artefact file with zip command, and upload zip file into AWS S3 bucket:
1
𝜆 zip hello-sam.zip README.md index.js template.yml
What AWS CloudFormation yaml file looks like:
Deploy application’s AWS CloudFormation stack with AWS SAM command:
Changeset created successfully. arn:aws:cloudformation:ap-southeast-2:123456789012:changeSet/samcli-deploy1581737165/48e53ff2-1b50-45d8-bbfd-97652f20d967
2020-02-15 14:26:10 - Waiting for stack create/update to complete
Successfully created/updated stack - hello-sam in None
NOTE: The --capabilities CAPABILITY_IAM option is necessary to authorise your stack to create IAM roles, which SAM applications do by default.
After application deployed, user subscribes notification will receive email titled - AWS Notification - Subscription Confirmation After confirmation, user will receive an email every time API is invoked.
Now log on AWS Console, have a look the resources this Lambda application used in CloudFormation, S3 Bucket, Lambda, IAM, SNS, CloudWatch, API Gateway.
After this Lambda application successfully deployed into AWS, you will receive an email asking whether you want to subscribe the SNS topic. You can also unsubscribe the SNS topic. You can manually test Lambda function in AWS Console.