AWS

Building an AWS SAM(Serverless Application Model) Project

CK CK 3788 
Created at  
898 0 0

AWS SAM (Serverless Application Model) is a framework that simplifies the building, deploying, and managing of serverless applications on AWS. It uses a YAML-based syntax to define the resources your application needs, such as Lambda functions, API Gateway endpoints, and DynamoDB tables. SAM allows developers to define their application's infrastructure and logic in a single file, making it easier to manage, test, and deploy serverless applications.

AWS SAM supports a wide range of programming languages for serverless applications, including Python, Node.js, Java, .NET, Go, Ruby, and PHP. This versatility allows developers to leverage their preferred languages and existing codebases when building serverless applications on AWS.

  • SAM is a framework that manages your infrastructure and application deployment, allowing you to choose the language for your application code independently within your project structure.
  • When setting up a SAM project, you don't directly select a language.

 

AWS SAM (Serverless Application Model) template

An AWS SAM (Serverless Application Model) template is a YAML or JSON document that defines the infrastructure and resources for a serverless application deployed on AWS. It simplifies the process of defining and deploying serverless applications by allowing you to specify resources like AWS Lambda functions, API Gateway endpoints, and DynamoDB tables in a declarative way. This makes it easier to manage and update your applications, as you can simply modify the template and redeploy your entire infrastructure with minimal effort.

Building an AWS SAM(Serverless Application Model) Project

AWS SAM template example

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
  getAllItemsFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/get-all-items.getAllItemsHandler
      Runtime: nodejs20.x
      Events:
        Api:
          Type: HttpApi
          Properties:
            Path: /
            Method: GET
    Connectors:
      MyConn:
        Properties:
          Destination:
            Id: SampleTable
          Permissions:
            - Read
  SampleTable:
    Type: AWS::Serverless::SimpleTable

 

AWS SAM CLI

AWS SAM CLI (Serverless Application Model Command Line Interface) is a command-line tool designed to help developers build, test, package, and deploy serverless applications on AWS. It provides a unified interface for working with AWS Lambda functions, API Gateway endpoints, and other serverless resources, making it easier to manage and deploy complex serverless architectures. SAM CLI supports various programming languages, simplifies the development process, and enables efficient local testing and debugging of serverless applications before deploying them to AWS. 
 
To install the AWS SAM CLI:

sudo pip3 install aws-sam-cli 

 

Verify the Installation:

sam --version

 

Run the "Hello World" example:

sam init --runtime nodejs14.x --name hello-world
cd hello-world
sam build
sam local invoke -e

 

Additional Configuration:

  • Configure AWS Credentials: Ensure you have configured your AWS credentials for access to your account.
  • Configure your AWS Region: Set the AWS region you want to work with using the following command:
aws configure

 

Use the SAM CLI:
Now you can use the SAM CLI to work with your AWS Serverless Application Model (SAM) projects. Some common commands include:

  • sam init: Initialize a new SAM project.
  • sam build: Build your project.
  • sam local invoke: Invoke your functions locally.
  • sam deploy: Deploy your application to AWS.
  • sam logs: View logs for your deployed functions.
Building an AWS SAM(Serverless Application Model) Project
Tags AWS Lambda AWS SAM AWS SAM CLI AWS SAM template SAM Serverless Application Serverless Application Model Facebook X
Comments 0
Similar posts
  1. AWS Lambda Code Example based on Python
    333
  2. AWS Lambda Example based on Teraform
    899
  3. Image Moderation Chatbot - a serverless chatbot on AWS that monitors chat channels and removes images suggestive or explicit image
    10,423
  4. Messaging Platform with Limited TPS based on the vendor
    194
  1. Creating a serverless Apache Kafka publisher using AWS Lambda
    562
  2. AWS System Design Example - Instagram Architecture
    1,916
  3. A Python script to create an EC2 Spot instance using boto3
    1,598
  4. A Python/PHP code to deregister anormalous instaces in Amazon ECS
    1,855
  5. Where to get AWS API Key at AWS Management Console?
    1,063
  6. Understanding Amazon Bedrock Agent for AI-based ChatBot
    642
  7. Media sharing service architecture in AWS
    10,364
  8. Enterprise Data Lake Architecture based on AWS
    10,403
  9. "502 Bad Gateway" Error easy to happen at the combination of nginx and node.js in AWS Elastic Beanstalk
    10,485
  10. How to Set Up and Deploy Containerized Applications with AWS ECS
    10,672
  11. Power of Containerized Deployment with AWS ECS
    10,594
  12. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    307
  13. Recommended Vector DB Structure for Amazon Bedrock Integration
    388
  14. Product Marketing & Recommendation Architecture in AWS for e-commerce website
    10,733
  15. What cause a 502 bad gateway error in AWS environment?
    443
  16. Teraform from the scratch
    1,352
  17. Check incomplete multipart uploads if AWS S3 storage size is abnormally big huge compared to the origin storage
    11,597
  18. Importing a wild card domain SSL certificate into AWS Certificate Manager
    10,348
  19. AWS Lambda Example based on Teraform
    899
  20. Simple AWS ECS example based on Teraform
    986
  21. Web front-end architecture in AWS for e-commerce website
    364
  22. Web Application Hosting provides the reliable, scalable, secure, and high-performance infrastructure
    10,614
  23. Time series processing architecture in AWS
    10,557
  24. Synchronous online gaming architecutre in AWS - Highly Available, Scalable & Elastic to support Millions of Players
    10,414
  25. Secure and Scalable LAMP Service Architecture in AWS
    10,658
  26. Live streaming / Static Content & Media Service based on AWS
    10,651
  27. Large scale messenger service architecture in AWS - Slack case study
    11,674
  28. Large scale computing based on huge data sets in AWS
    10,607
  29. Image Moderation Chatbot - a serverless chatbot on AWS that monitors chat channels and removes images suggestive or explicit image
    10,423
  30. Financial services grid computing in AWS
    10,354
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,732
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    86
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    198
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    234
  17. The Concept of Scaffolding in AI Agents
    222
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    576
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    253
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    328
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    197
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252