Cloud service · AWS · Updated

AWS Serverless Application Model (AWS SAM)

In short

AWS Serverless Application Model (AWS SAM) is a framework for building serverless applications that simplifies the process of defining, deploying, and managing serverless infrastructure on AWS using familiar infrastructure as code techniques.

Cloud Services Hub →

10 key features of AWS Serverless Application Model (AWS SAM)

AWS SAM streamlines serverless application development by offering infrastructure as code, seamless AWS integration, local testing, simple deployment, and built-in best practices.

01
Infrastructure as Code

AWS SAM allows you to define your serverless applications and their resources using simple YAML configuration. This enables version-controlled, repeatable, and automated setups.

02
Seamless Integration with AWS Services

It integrates tightly with AWS services such as Lambda, DynamoDB, and API Gateway, making it easier to compose complex applications with these managed services.

03
Local Testing and Debugging

AWS SAM provides tools for local testing and debugging of serverless applications, making development faster and more efficient.

04
Simple Deployment

SAM simplifies the deployment process of your serverless applications by using CloudFormation under the hood, allowing you to deploy with a single command.

05
Built-in Best Practices

AWS SAM includes a number of built-in best practices for security, reliability, and efficiency, helping developers follow AWS best practices with less effort.

06
AWS SAM Connectors

AWS SAM connectors define permissions between AWS resources in SAM templates. SAM transforms these definitions into the IAM permissions needed for the specified interactions.

07
Continuous Cloud Sync

The SAM CLI's sam sync command automatically synchronizes local changes to the cloud to accelerate development and cloud testing.

08
Terraform Application Testing

The AWS SAM CLI supports local debugging and testing of Lambda functions and layers in Terraform serverless applications.

09
Container-based Builds

SAM can build functions inside Lambda-compatible containers using --use-container, ensuring dependencies use the correct architecture and glibc versions for the Lambda runtime environment.

10
CI/CD Pipeline Support

The AWS SAM CLI includes features for creating continuous integration and continuous delivery (CI/CD) pipelines for serverless applications.

Where AWS Serverless Application Model (AWS SAM) is used

AWS Serverless Application Model (SAM) enables easy deployment and management of serverless applications for use cases such as building API backends, automating business processes, developing chatbots, processing data in real-time, and executing scheduled tasks.

  1. 01
    Building API Backends

    AWS SAM allows developers to easily build serverless API backends that automatically scale up and down based on demand. With SAM, you can define APIs directly in your template and connect them with Lambda functions to process HTTP requests. This makes it straightforward to create and deploy RESTful APIs without managing servers.

  2. 02
    Automating Business Processes

    AWS SAM facilitates the automation of business processes by allowing developers to integrate various AWS services. By defining event-driven Lambda functions, businesses can automate workflows, such as order processing, file conversions, or data validations, without provisioning or managing servers, thus reducing operational complexity and cost.

  3. 03
    Developing Chatbots

    With AWS SAM, developers can easily deploy and manage serverless infrastructure for chatbots. By leveraging Amazon Lex for conversational interfaces and connecting it with Lambda for processing logic, SAM streamlines the deployment of chatbots across various platforms, allowing businesses to engage with customers efficiently.

  4. 04
    Real-time Data Processing

    AWS SAM is ideal for setting up serverless architectures capable of processing data streams in real-time. Whether it's processing logs, social media feeds, or real-time analytics, SAM, in conjunction with AWS Lambda and Amazon Kinesis, enables scalable, on-the-fly data processing without the need to manage underlying infrastructure.

  5. 05
    Scheduled Tasks

    AWS SAM simplifies the execution of scheduled tasks using AWS Lambda functions. This is particularly useful for tasks such as database cleanups, inventory updates, or periodic data processing. By defining the schedule in the SAM template, tasks can be automated without the overhead of server maintenance.

How AWS Serverless Application Model (AWS SAM) is priced

AWS SAM follows a Pay-As-You-Go model with added benefits of a free tier that includes 1 million free requests per month and 400,000 GB-seconds of compute time for AWS Lambda.

No Additional Charge

AWS SAM is available at no additional charge; you pay for the AWS resources your application uses under each service's pricing. Pricing is based on the actual amount of resources that your application consumes, which could include Lambda executions, API Gateway calls, and DynamoDB read/write operations.

Services AWS Serverless Application Model (AWS SAM) works with

Amazon API GatewayAmazon API Gateway

AWS SAM defines REST APIs and HTTP APIs, connects their routes to Lambda functions, and configures features such as authorization and custom domains. Its local API emulation lets you test requests before deployment.

Amazon AthenaAmazon Athena

AWS SAM provides an Athena query policy template that grants a function permissions to run and inspect queries, with access to the specified query-results bucket.

Amazon CloudWatchAmazon CloudWatch

AWS SAM configures CloudWatch Logs and scheduled or rule-based function triggers, and its policy templates grant permissions for publishing metrics and managing dashboards. The sam logs command retrieves logs from deployed applications.

Amazon CognitoAmazon Cognito

AWS SAM configures Cognito user pools as API authorizers and connects Lambda functions to user-pool triggers. It also provides a policy template for reading user-pool information.

Amazon ComprehendAmazon Comprehend

AWS SAM provides a Comprehend policy template that grants a function permissions for text-analysis operations, such as detecting sentiment or entities.

Amazon Data FirehoseAmazon Data Firehose

AWS SAM provides policy templates for writing records to a specified Firehose delivery stream or managing delivery streams.

Amazon DynamoDBAmazon DynamoDB

AWS SAM provisions DynamoDB tables through its SimpleTable resource and configures DynamoDB Streams to invoke Lambda functions. Connectors and policy templates generate permissions for table access, stream consumption, and backup operations.

Amazon EC2Amazon EC2

AWS SAM includes policy templates that grant functions permissions to describe EC2 resources and AMIs or copy machine images. These support serverless automation that inventories instances or manages images.

Amazon Elastic File System (Amazon EFS)Amazon Elastic File System (Amazon EFS)

AWS SAM configures EFS access-point mounts for Lambda functions through their file-system settings. Its EFS policy template grants the permissions needed to mount and access the file system.

What is AWS Serverless Application Model (AWS SAM)

2 min read

The AWS Serverless Application Model, known as AWS SAM, serves as a comprehensive framework designed for the development and deployment of serverless applications. It is specifically tailored for use within the AWS ecosystem, streamlining the process to build scalable, high-performing services without having to manage servers. The serverless approach significantly reduces the operational burden on developers, allowing them to focus on writing code that adds direct value to their business or project, rather than concerning themselves with the underlying infrastructure. 

AWS SAM extends AWS CloudFormation, providing a simplified syntax to express functions, APIs, databases, and event source mappings. With this model, the definition of an application's infrastructure becomes as straightforward as describing its components in a simple configuration file. This SAM template, typically written in YAML, acts as a blueprint for AWS to understand how to provision and configure the necessary resources for the serverless application to run. An essential part of AWS SAM is the SAM CLI (Command Line Interface), a tool that facilitates local development and testing of serverless applications. It empowers developers to run their applications in an environment that closely mimics AWS, offering a more accurate development experience. 

A SAM template can combine standard CloudFormation syntax with SAM's shorthand syntax in the same template.

Through the SAM CLI, developers can invoke functions locally, start a local API Gateway from a SAM template, validate SAM templates, and even generate sample payloads for various event sources. This local development capability accelerates the feedback loop, enabling rapid iteration and testing. Integration with other AWS services is a cornerstone of the SAM framework, ensuring that serverless applications can easily leverage the rich ecosystem of AWS offerings. This includes services like Amazon DynamoDB for databases, Amazon API Gateway for creating RESTful APIs, and Amazon EventBridge for event-driven architectures, among others. Not only does this facilitate the development of complex, distributed applications but it also ensures that these applications can scale automatically and remain highly available without direct intervention from the developer. 

Security is another critical aspect addressed by AWS SAM. It seamlessly integrates with AWS Identity and Access Management (IAM), allowing developers to define granular access control to their serverless applications. By specifying IAM roles and policies directly within the SAM template, developers can enforce stringent security measures, ensuring that the application adheres to the principle of least privilege. 

In conclusion, AWS SAM represents an evolutionary leap in the realm of serverless application development. By abstracting away much of the complexity associated with infrastructure management, it allows developers to harness the full potential of serverless computing. Through its simplified syntax, local development capabilities, deep integration with AWS services, and robust security features, AWS SAM provides a formidable framework for building, deploying, and managing serverless applications at scale.

AWS Serverless Application Model (AWS SAM) exam questions

Real practice exam questions on AWS Serverless Application Model (AWS SAM), with the correct answer and its explanation. Answer them with every option in the exam simulator.

DEA-C01

A data engineer uses AWS SAM to deploy a pipeline into separate development and production stacks. Each stack creates an Amazon DynamoDB table with the logical ID TransformedRecords and an AWS::Serverless::Function that writes transformed records by calling PutItem. The table's physical name is generated during deployment. The function reads the target table name from the TABLE_NAME environment variable.

SAM generates the function's execution role, which currently has only logging permissions. The engineer must configure each function to write to its own stack's table, grant only the required DynamoDB action, and avoid hardcoded table names or ARNs.

Which configuration meets these requirements?

Show answerCORRECT ANSWER

Set TABLE_NAME to !Ref TransformedRecords. In the function's Policies property, add an IAM statement allowing dynamodb:PutItem with Resource set to !GetAtt TransformedRecords.Arn.

For a DynamoDB table, Ref returns the table name, and GetAtt with Arn returns its ARN. The environment variable therefore identifies the correct stack-specific table, while the policy grants the function's generated execution role only PutItem access to that table.

DOP-C02

A company uses AWS CodeBuild and the AWS SAM CLI to generate artifacts for a serverless application. Several Python Lambda functions use a shared AWS::Serverless::LayerVersion resource with the logical ID NativeToolsLayer and ContentUri set to tools/. The functions invoke a compiled helper at /opt/bin/report-helper.

The tools/ directory contains C++ source code and a Makefile with an existing compilation recipe, but it does not contain the compiled executable. The CodeBuild environment has a compiler and libraries compatible with the functions' Lambda runtime and x86_64 architecture. The functions' Python dependencies already build successfully.

A DevOps engineer must integrate compilation of the helper into sam build so that the generated layer artifact contains the executable at the required location. The engineer must use SAM's custom build mechanism without adding a separate compilation step to the buildspec or committing compiled files to the repository.

Which configuration meets these requirements?

Show answerCORRECT ANSWER

Add Metadata with BuildMethod: makefile to NativeToolsLayer. In tools/Makefile, define build-NativeToolsLayer to run the compilation recipe and copy the executable to $(ARTIFACTS_DIR)/bin/report-helper.

SAM supports custom Makefile builds for layers. BuildMethod: makefile selects this mechanism, and SAM invokes the build target named build- followed by the resource's logical ID. The recipe must place its output in ARTIFACTS_DIR. Lambda extracts layer contents under /opt, so bin/report-helper in the layer becomes /opt/bin/report-helper.

DVA-C02

A developer maintains a serverless application whose template defines several API Gateway REST API routes and their Lambda function integrations. An existing HTTP test suite sends requests to a configurable base URL and checks route selection, query string handling, response headers, and response bodies. The functions do not call external services.

Before deploying changes, the developer must run the test suite unchanged against the local application without creating AWS resources. Docker and the required development tools are installed.

Which approach meets these requirements?

Show answerCORRECT ANSWER

Run `sam build`, then run `sam local start-api`. Configure the test suite's base URL to use the local HTTP endpoint and execute the tests.

`sam local start-api` uses the template's API definitions to expose local HTTP routes and invoke the associated Lambda functions in Docker containers. The existing HTTP tests can exercise route selection, request handling, and responses without deploying AWS resources. This does not replace subsequent testing of deployed service behavior.

Practice AWS Serverless Application Model (AWS SAM) in a full exam

Questions on AWS Serverless Application Model (AWS SAM) in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

Learn AWS Serverless Application Model (AWS SAM) in lessons

4 short lessons on AWS Serverless Application Model (AWS SAM) in 2 certification courses.

Open the lessons

AWS architecture icons are the property of Amazon Web Services. BlowStack is not affiliated with or endorsed by AWS.