AWS SAM and Serverless Applications
Learn how to build, test, and deploy serverless applications using AWS SAM, focusing on Lambda, API Gateway, and DynamoDB with the SAM CLI.
We'll cover the following...
Traditionally, applications were designed on request/response models. The client would send requests to the backend, consisting of multiple classes to process the request and return responses. Since such applications are all bundled in one package, they are also called monolith applications.
With the arrival of cloud computing, developers deployed their monolith software applications on virtual machines on the cloud, such as an EC2 instance. They would install an operating system and the application code on these machines and configure a firewall to secure the application. If the demand spiked, they would spin up new EC2 instances, perform installations, and set up proxies to balance the traffic. In simple terms, they manually up- and down-scaled the compute resources.
However, concerns about simultaneous maintenance and development can be draining for the developer. This is where serverless computing comes in as the savior.
Serverless architecture is an architectural approach in which components, such as authentication, database, and business logic, are provided by serverless services. The entire application is designed to execute without the need to deploy or configure any servers on the developer’s end.
Serverless Application Model (SAM)
AWS Serverless Application Model (AWS SAM) is an open-source framework specifically designed to simplify the development of serverless applications. It extends AWS CloudFormation and provides shorthand syntax to define functions, APIs, databases, and event source mappings.
SAM has two major components: the SAM template and the SAM CLI.
Structure of SAM templates
SAM templates are YAML-based configuration files that define the infrastructure and configuration of our serverless application. These templates are essentially CloudFormation templates with simplified syntax for serverless resources.
AWSTemplateFormatVersion: This section specifies the version of the AWS CloudFormation template format being used. While this is a required field, it does not usually change between projects. For example, most templates use
2010-09-09
, which indicates compatibility with the foundational version of CloudFormation. Though not critical to application behavior, it is required for SAM to parse the template correctly.Transform:
AWS::Serverless-2016-10-31
This field is specific ...