AWS Logo
Menu
Deploying Serverless applications with AWS SAM

Deploying Serverless applications with AWS SAM

Learn how to build and deploy serverless applications using AWS SAM with best practices, local testing, and streamlined CI/CD workflows.

Published Apr 30, 2025
Serverless architectures gained significant traction following the introduction of AWS Lambda in 2014. This architectural paradigm enables developers to build and operate applications without the need to provision or manage underlying server infrastructure. Serverless solutions automatically scale in response to workload demands, promoting greater efficiency and cost optimization. Key AWS services such as AWS Lambda, which runs code in response to defined events, and Amazon API Gateway, which facilitates the creation and management of APIs, are central to enabling these capabilities.
To streamline the deployment of serverless applications, a suite of developer tools has emerged over the years. Among these, the AWS Serverless Application Model (SAM)—an open-source framework introduced by AWS—was designed to simplify the development, testing, and deployment of serverless applications in the AWS environment. Our team began experimenting with AWS SAM in 2018, during its early stages. While it provided a promising approach to managing serverless deployments using simplified configuration files and native integration with AWS services, its initial feature set was limited compared to more mature tools at the time, such as the Serverless Framework, which offered broader multi-cloud support and a richer plugin ecosystem.
Over time, tools like AWS SAM have evolved significantly, becoming a core part of the modern serverless development lifecycle.

Recently, Serverless.com changed their pricing model

As announced by Serverless Inc., version 4 (V4) of the Serverless Framework introduces a new pricing model that marks a significant shift in its licensing structure.
Beginning with V4, the Serverless Framework CLI will remain free for individual developers and small businesses; however, organizations with annual revenues exceeding $2 million will now be required to obtain a commercial subscription to use the framework. This change applies exclusively to version 4 and beyond—version 3 (V3) will continue to receive critical security patches and bug fixes throughout 2024, but will not be subject to the new licensing terms.
This revised pricing strategy introduces new considerations for organizations evaluating cost-effective solutions for managing serverless deployments. As a result, it's an opportune moment to **reassess the capabilities and enhancements introduced in the latest versions of the AWS Serverless Application Model (SAM), which continues to evolve as a robust, AWS-native alternative for building and deploying serverless applications efficiently.

AWS Serverless Application Model (SAM)

Overview

AWS Serverless Application Model (SAM) is built around two core components: AWS SAM templates and the AWS SAM Command Line Interface (CLI).
The AWS SAM templates provide a simplified, declarative syntax for defining Infrastructure as Code (IaC), specifically tailored for serverless application development. These templates are an abstraction over AWS CloudFormation, allowing developers to define functions, APIs, databases, and event source mappings with minimal configuration. Once defined, SAM templates can be seamlessly deployed using native CloudFormation tooling, enabling consistent, repeatable deployments with built-in support for version control and automation.
Complementing the templates, the AWS SAM CLI is a powerful command-line tool that streamlines the local development, testing, and deployment of serverless applications on AWS. It enables developers to emulate AWS Lambda functions and API Gateway locally, validate their templates, package application artifacts, and deploy them directly to the cloud—all from the local development environment. This facilitates rapid iteration and debugging, improving developer productivity and reducing time-to-market.
Together, these components make AWS SAM a comprehensive framework for building, testing, and managing serverless applications in a production-grade AWS environment.

What’s new since 2018?

Since its introduction in 2018, the AWS Serverless Application Model (AWS SAM) has matured into a comprehensive framework, continuously evolving to simplify the process of building, testing, and deploying serverless applications on AWS. Over the years, AWS SAM has incorporated a range of powerful features aimed at improving developer productivity and expanding the scope of serverless development.

Key Enhancements in AWS SAM

  • Introduction of sam build: The addition of the sam build command to the AWS SAM CLI streamlines the process of compiling serverless applications along with their dependencies. This enables developers to seamlessly test applications locally before deploying to the cloud. It abstracts much of the manual build configuration, improving build consistency and reducing errors. Learn more about building applications.
  • Support for Nested Applications and Layers: AWS SAM now supports nested applications, allowing you to modularize complex architectures by referencing reusable serverless components. Additionally, support for Lambda Layers enables better code reuse and dependency management across multiple functions.
  • Orchestration with AWS Step Functions: AWS SAM introduced the ability to define Step Functions state machines directly within SAM templates using the AWS::Serverless::StateMachine resource type. This allows for orchestrating complex workflows within a serverless architecture, making it easier to model long-running and distributed processes.
  • Local Testing with Warm Containers: To improve the fidelity of local testing, SAM CLI now supports warm containers when using sam local start-api and sam local start-lambda. This better simulates AWS Lambda’s warm start behavior, which is crucial for performance tuning and troubleshooting.
  • Enhanced Debugging Capabilities: Integration with AWS Toolkits for popular IDEs (such as VS Code, JetBrains, and Eclipse) now enables step-through debugging across a wider range of runtimes and configurations. This provides developers with a more interactive and efficient debugging experience.
  • Terraform Integration for Local Testing: The AWS SAM CLI now offers support for local debugging and testing within Terraform-based projects. This allows teams using Terraform for infrastructure provisioning to leverage SAM’s local emulation features, bridging the gap between infrastructure as code and serverless application development.
  • Advanced Observability and Monitoring: AWS SAM has also incorporated support for key AWS services such as AWS X-Ray, enabling developers to trace, analyze, and debug distributed serverless applications with greater visibility into execution flows and performance bottlenecks.

With the significant evolution of AWS SAM, developers are now equipped with a robust toolkit that supports everything from modular architecture to seamless debugging and testing. To gain hands-on experience with these new capabilities, let’s create a sample project that demonstrates how they can be used in practice.

Creating and deploying a Serverless application with AWS SAM

Prerequisites

First, let’s download and install the latest version of the AWS SAM CLI following Installing the AWS SAM CLI.
Once done, you should be able to list all available commands by typing sam -h.

Creating the application

Let’s create our application. There are several templates available to test and deploy quickly a Serverless application to the cloud. To bootstrap a demo environment, type sam init and select the Hello World Example with PowerTools for AWS Lambda.

What are Powertools for AWS Lambda?

Powertools for AWS Lambda is an open-source developer toolkit designed to accelerate serverless application development on AWS while promoting adherence to serverless best practices. It provides a suite of high-quality utilities that simplify the implementation of common operational and architectural patterns in Lambda-based applications. By leveraging Powertools, developers can improve code consistency, observability, and reliability, all while enhancing developer productivity and reducing time to market.

Key Features of Powertools for AWS Lambda

  • Distributed Tracing: Powertools offers seamless integration with AWS X-Ray, enabling end-to-end tracing across multiple AWS services such as Lambda, API Gateway, and Step Functions. This makes it easier to visualize application flows, identify performance bottlenecks, and diagnose failures in complex distributed systems.
  • Structured Logging: With its built-in logger, Powertools enforces structured logging formats (e.g., JSON), which enhance the clarity and consistency of log messages. This structured approach makes it easier to parse and query logs in Amazon CloudWatch Logs Insights, enabling more efficient monitoring and diagnostics.
  • Resilience Patterns (Retries & Circuit Breakers): Powertools includes utilities for automated retries and circuit breaker implementations, helping developers build more resilient applications that can gracefully handle transient failures and downstream service disruptions.
  • Robust Error Handling: The toolkit simplifies error management by providing decorators and utilities to automatically capture, log, and contextualize exceptions. It also supports integration with AWS Step Functions, enabling cleaner coordination and state management in workflows.
  • Additional Utilities: Beyond the core features, Powertools continues to expand with a range of additional helpers, including input validation, parameter store integration, feature flags, and metrics collection using Amazon CloudWatch Embedded Metrics.

Powertools for AWS Lambda is actively maintained and available in multiple programming languages, including Python, TypeScript, and Java, making it a versatile addition to any serverless development workflow. Its modular, plug-and-play design allows teams to adopt only the features they need, ensuring flexibility without added complexity.

Building the application

Now that we have created the project, the next step is to package the application. The sam build command is a part of the AWS SAM CLI, which will help us build and package the serverless application using AWS SAM templates.

Deploying the application

Once built, we can deploy the application with the sam deploy command. The deployment process leverages CloudFormation to deploy the application as a CloudFormation stack.

Collecting traces

Now that, that our application is deployed, you can call the endpoint deployed to interact with the application. In our example, the endpoint is displayed in the “Outputs” section of the deployment phase (https://x4anr51xta.execute-api.us-east-1.amazonaws.com/Prod/hello). Each call will be tracked thanks to the Amazon X-Ray integration. Amazon X-Ray is a distributed tracing service provided by AWS that helps developers analyze and debug applications, particularly those built using serverless architecture. By running the sam traces command, you can see various figures including statistics to monitor the performance of serverless applications.

Reviewing logs

The sam logs command allows developers to retrieve, filter, and view logs generated by AWS Lambda functions. It simplifies the process of debugging and monitoring serverless applications by providing direct access to the log data from AWS CloudWatch Logs.

Testing the application

During the development, you can either deploy in a local container or deploy to a development AWS account and test it. To deploy the application in AWS, run the sam deploy command and wait CloudFormation to deploy your new code.
During the development phase, the sam sync command is a valuable addition. It listens for changes and deploys your updates upon saving, eliminating the need to run the sam deploy command every time you want to deploy. The sync command takes care of that.

Deleting your application

Finally, you can clean the application with the sam delete command which takes care of deleting all assets deployed in the AWS account.

Conclusion

In summary, this blog post has highlighted the ongoing evolution of the AWS Serverless Application Model (AWS SAM), demonstrating how its expanding feature set is making serverless application development more streamlined, scalable, and accessible. With continuous enhancements such as improved local testing, debugging support, Step Functions orchestration, and native integration with a wide range of AWS services, AWS SAM is becoming an increasingly powerful framework for modern cloud-native development.
As an open-source project developed and maintained by AWS in collaboration with the community, AWS SAM benefits from active contributions, timely updates, and a robust support ecosystem. Its well-structured and comprehensive documentation further enhances the developer experience, reducing the learning curve and accelerating adoption.
Given its growing capabilities, strong AWS-native alignment, and enterprise-grade tooling, AWS SAM stands out as a compelling and reliable alternative to the Serverless Framework, particularly for teams building exclusively within the AWS ecosystem.

Never stop learning

For those looking to stay informed on the latest advancements in serverless technologies, there is no shortage of high-quality resources available. One particularly valuable platform is Serverless Land—a curated hub maintained by AWS that offers a wealth of content including technical blogs, tutorials, workshops, and reference architectures. It serves as an essential resource for both beginners and experienced practitioners seeking to deepen their understanding of AWS serverless services and best practices.
Additionally, developers are encouraged to follow the ongoing developments in Powertools for AWS Lambda, as this toolkit continues to evolve with new features aimed at enhancing observability, resilience, and maintainability in serverless applications.
To remain ahead of the curve, make it a habit to regularly review official AWS serverless updates, blog posts, release notes, and community contributions, all of which offer critical insights into emerging tools, patterns, and performance optimization techniques within the AWS serverless ecosystem.

OK, folks that’s it for this post. Have a nice day guys…… Stay tuned…..!!!!!

Don’t forget to like & share this post on social networks!!! I will keep on updating this blog. Please do follow!!!
 

Comments