A serverless application is a combination of Lambda functions, event sources, and other resources that work together to perform tasks. Note that a serverless application is more than just a Lambda function—it can include additional resources such as APIs, databases, and event source mappings.
Components:
AWS SAM template specification
AWS SAM templates are an extension of AWS CloudFormation templates, with some additional components that make them easier to work with.
Written in YAML
Can specify other resources not just Lambda
AWS SAM command-line interface (AWS SAM CLI).
sam build
aws cloudformation package / sam package
awas cloudformation deploy / sam deploy
Template Anatomy:
Transform declaration
Transform: AWS::Serverless-2016-10-31
Required
Globals section:
Globals
Defines properties that are common to all your serverless functions and APIs
Resources section
can contain a combination of AWS CloudFormation resources and AWS SAM resources
Resources:
AWS::Serverless::Api – Creates a collection of Amazon API Gateway resources and methods that can be invoked through HTTPS endpoints
AWS::Serverless::Function – Creates an AWS Lambda function, an AWS Identity and Access Management (IAM) execution role, and event source mappings that trigger the function.
AWS::Serverless::SimpleTable – Creates a DynamoDB table with a single attribute primary key. It is useful when data only needs to be accessed via a primary key.
Parameters section
Objects that are declared in the Parameters section cause the sam deploy --guided command to present additional prompts to the user.
Building
Gathers the build artifacts of your application’s dependencies and places them in the proper format and location for next steps, such as locally testing, packaging, and deploying.
CLI sam build
transform SAM template into CloudFormation template together with the application code
Testing
Can invoke your function locally
CLI sam local invoke command and providing its function logical ID and an event file
Packaging
Make application available for others to find and deploy
CLI aws cloudformation package / sam package
zip and upload to S3 bucket
Deploying
Can use CICD. For AWS use CodePipeline
CLI awas cloudformation deploy / sam deploy
Find the package from S3 and load to CloudFormation