Convert Figma logo to code with AI

aws logoaws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM

6,505
1,168
6,505
461

Top Related Projects

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

24,977

OpenFaaS - Serverless Functions Made Simple

Quick Overview

AWS SAM CLI (Serverless Application Model Command Line Interface) is an open-source tool for building, testing, and deploying serverless applications on AWS. It provides a simplified way to define and manage serverless resources, allowing developers to focus on writing code rather than managing infrastructure.

Pros

  • Simplifies serverless application development and deployment on AWS
  • Provides local testing and debugging capabilities for Lambda functions
  • Integrates well with existing AWS services and tools
  • Supports multiple programming languages and runtimes

Cons

  • Limited to AWS ecosystem, not suitable for multi-cloud or non-AWS deployments
  • Learning curve for developers new to serverless concepts or AWS
  • Some advanced features may require additional configuration or workarounds
  • Local testing environment may not perfectly replicate AWS production environment

Code Examples

  1. Initializing a new SAM project:
sam init --runtime python3.9 --name my-sam-app

This command creates a new SAM project with Python 3.9 runtime.

  1. Building the SAM application:
sam build

This command builds the application and prepares it for deployment.

  1. Deploying the SAM application:
sam deploy --guided

This command deploys the application to AWS, with an interactive guided deployment process.

Getting Started

To get started with AWS SAM CLI:

  1. Install AWS SAM CLI:

    pip install aws-sam-cli
    
  2. Configure AWS credentials:

    aws configure
    
  3. Create a new SAM project:

    sam init
    
  4. Build and deploy your application:

    sam build
    sam deploy --guided
    

For more detailed instructions, refer to the AWS SAM CLI documentation.

Competitor Comparisons

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

Pros of Serverless

  • Multi-cloud support (AWS, Azure, GCP, etc.)
  • Extensive plugin ecosystem
  • More flexible and customizable deployment options

Cons of Serverless

  • Steeper learning curve
  • Potentially more complex configuration
  • Less integrated with AWS-specific features

Code Comparison

Serverless:

service: my-service
provider:
  name: aws
  runtime: nodejs14.x
functions:
  hello:
    handler: handler.hello

SAM CLI:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs14.x

Key Differences

  • Serverless supports multiple cloud providers, while SAM CLI is AWS-specific
  • SAM CLI uses AWS CloudFormation syntax, Serverless uses its own configuration format
  • Serverless offers more extensive customization options, but SAM CLI provides tighter AWS integration
  • SAM CLI is better suited for AWS-focused projects, while Serverless is more versatile for multi-cloud deployments
  • Both tools support local testing and debugging, but SAM CLI's integration with AWS services is more seamless

Use Cases

  • Choose Serverless for multi-cloud projects or when extensive customization is required
  • Opt for SAM CLI when working exclusively with AWS and prefer native AWS tooling and integration
20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Pros of Pulumi

  • Supports multiple cloud providers, not limited to AWS
  • Uses familiar programming languages (Python, JavaScript, etc.) instead of YAML
  • Offers more flexibility and control over infrastructure as code

Cons of Pulumi

  • Steeper learning curve for those familiar with YAML-based templates
  • Requires more setup and configuration compared to SAM CLI
  • May be overkill for simple serverless applications

Code Comparison

SAM CLI (YAML):

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs14.x
      CodeUri: ./src

Pulumi (JavaScript):

const lambda = new aws.lambda.Function("myFunction", {
    code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./src"),
    }),
    handler: "index.handler",
    runtime: "nodejs14.x",
});

Both SAM CLI and Pulumi are powerful tools for infrastructure as code, but they cater to different needs. SAM CLI is more focused on AWS serverless applications, while Pulumi offers a broader scope for multi-cloud deployments. The choice between them depends on your specific project requirements, team expertise, and desired level of control over infrastructure.

42,146

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

Pros of Terraform

  • Multi-cloud support, allowing infrastructure management across various providers
  • More extensive ecosystem with a larger community and wider range of available modules
  • Declarative syntax for defining infrastructure as code, promoting consistency and reusability

Cons of Terraform

  • Steeper learning curve, especially for those new to infrastructure as code
  • Requires manual state management, which can be complex in team environments
  • Less tightly integrated with AWS-specific features compared to SAM CLI

Code Comparison

SAM CLI (template.yaml):

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler

Terraform (main.tf):

resource "aws_lambda_function" "my_function" {
  filename      = "lambda_function_payload.zip"
  function_name = "my_function"
  role          = aws_iam_role.lambda_role.arn
  handler       = "index.handler"
}

Both tools use declarative syntax to define infrastructure, but Terraform's HCL (HashiCorp Configuration Language) is more verbose and flexible, while SAM CLI's YAML-based templates are more concise and AWS-specific. SAM CLI is tailored for serverless applications on AWS, whereas Terraform offers a broader scope for managing various types of infrastructure across multiple cloud providers.

24,977

OpenFaaS - Serverless Functions Made Simple

Pros of faas

  • Platform-agnostic: Works with any cloud provider or on-premises infrastructure
  • Supports multiple programming languages and frameworks
  • Active community and extensive ecosystem of templates and functions

Cons of faas

  • Steeper learning curve compared to SAM CLI
  • Less integrated with cloud provider-specific services
  • May require more setup and configuration for complex deployments

Code Comparison

SAM CLI (Python):

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: app.lambda_handler

faas (YAML):

version: 1.0
provider:
  name: openfaas
  gateway: http://127.0.0.1:8080
functions:
  hello-world:
    lang: python3
    handler: ./hello-world
    image: hello-world:latest

Both frameworks use YAML for configuration, but SAM CLI is more tightly integrated with AWS services, while faas offers a more flexible, cloud-agnostic approach. SAM CLI's template focuses on AWS-specific resources, whereas faas configuration is centered around function definitions and deployment settings applicable to various platforms.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

AWS SAM CLI

Apache 2.0 License SAM CLI Version Install pip

Installation | Blogs | Videos | AWS Docs | Roadmap | Try It Out | Slack Us

The AWS Serverless Application Model (SAM) CLI is an open-source CLI tool that helps you develop serverless applications containing Lambda functions, Step Functions, API Gateway, EventBridge, SQS, SNS and more. Some of the features it provides are:

  • Initialize serverless applications in minutes with AWS-provided infrastructure templates with sam init
  • Compile, build, and package Lambda functions with provided runtimes and with custom Makefile workflows, for zip and image types of Lambda functions with sam build
  • Locally test a Lambda function and API Gateway easily in a Docker container with sam local commands on SAM and CDK applications
  • Sync and test your changes in the cloud with sam sync in your developer environments
  • Deploy your SAM and CloudFormation templates using sam deploy
  • Quickly create pipelines with prebuilt templates with popular CI/CD systems using sam pipeline init
  • Tail CloudWatch logs and X-Ray traces with sam logs and sam traces

Recent blogposts and workshops

  • Speeding up incremental changes with AWS SAM Accelerate and Nested Stacks - Read blogpost here.

  • Develop Node projects with SAM CLI using esbuild - and use SAM Accelerate on Typescript projects. Read blogpost here.

  • Speed up development with SAM Accelerate - quickly test your changes in the cloud. Read docs here.

  • AWS Serverless Developer Experience Workshop: A day in a life of a developer - This advanced workshop provides you with an immersive experience as a serverless developer, with hands-on experience building a serverless solution using AWS SAM and SAM CLI.

  • The Complete SAM Workshop - This workshop is a great way to experience the power of SAM and SAM CLI.

  • Getting started with CI/CD? SAM pipelines can help you get started - This workshop walks you through the basics.

  • Get started with Serverless Application development using SAM CLI - This workshop walks you through the basics.

Get Started

To get started with building SAM-based applications, use the SAM CLI. SAM CLI provides a Lambda-like execution environment that lets you locally build, test, debug, and deploy AWS serverless applications.

Next Steps: Learn to build a more complex serverless application.

What is this Github repository? 💻

This Github repository contains source code for SAM CLI. Here is the development team talking about this code:

SAM CLI code is written in Python. Source code is well documented, very modular, with 95% unit test coverage. It uses this awesome Python library called Click to manage the command line interaction and uses Docker to run Lambda functions locally. We think you'll like the code base. Clone it and run make pr or ./Make -pr on Windows!

Related Repositories and Resources

Contribute to SAM

We love our contributors ❤️ We have over 100 contributors who have built various parts of the product. Read this testimonial from @ndobryanskyy to learn more about what it was like contributing to SAM.

Depending on your interest and skill, you can help build the different parts of the SAM project;

Enhance the SAM Specification

Make pull requests, report bugs, and share ideas to improve the full SAM template specification. Source code is located on Github at aws/serverless-application-model. Read the SAM Specification Contributing Guide to get started.

Strengthen SAM CLI

Add new commands, enhance existing ones, report bugs, or request new features for the SAM CLI. Source code is located on Github at aws/aws-sam-cli. Read the SAM CLI Contributing Guide to get started.

Update SAM Developer Guide

SAM Developer Guide provides a comprehensive getting started guide and reference documentation. Source code is located on Github at awsdocs/aws-sam-developer-guide. Read the SAM Documentation Contribution Guide to get started.

Join the SAM Community on Slack

Join the SAM developers channel (#samdev) on Slack to collaborate with fellow community members and the AWS SAM team.