Comparing the Serverless framework with AWS SAM
The full setup is explained in my blog post: Comparing AWS SAM with Serverless framework.
Make sure you have configured AWS credentials for your account. These credentials must have the permissions to create the resources defined in the stacks.
Please note that all Lambda function assume to be ran in the
eu-west-1 region. You must change the NodeJS code to reflect the correct region. Find the following line:
Deploy the serverless.yaml file through the following steps;
- If required, change the region to the region you wish to use (line 7)
your_email_addresswith proper values. The bucket shouldn't yet exist. Your e-mail adress is used to attach it to an SNS topic.
serverless deploy -v. This will generate a CloudFormation stack that is deployed to your AWS account. You will receive an e-mail that you are now subscribed to an SNS topic.
serverless remove to destroy the stack.
Serverless Application Model (SAM)
Deploy the template.yaml file through the following steps:
- Create a new S3 bucket in your AWS account. This is used to upload the CloudFormation and Lambda artifacts to by SAM.
your_email_addresswith your e-mail address. This is used to attach it to an SNS topic.
- Run the following command to generate the CloudFormation:
sam package --template-file template.yaml --s3-bucket [your_s3_bucket] --output-template-file package.yaml. Replace
your_s3_bucketwith the name of the bucket you just created.
- Run the following command to deploy the generated stack:
sam deploy --template-file package.yaml --stack-name serverless-application --capabilities CAPABILITY_IAM
aws cloudformation delete-stack --stack-name serverless-application to destroy the stack.