AWS Developer Associate (DVA-C01) Review Material – Lambda and SAM

Lambda

  • General
    • A compute service that lets you run code without provisioning or managing servers.
    • Best suited for shorter, event-driven workloads, since Lambda functions run for up to 15 minutes per invocation.
    • Concepts:
      • Function
      • Trigger
      • Event
      • Execution environment
      • Instruction set architecture
      • Deployment package
      • Runtime
      • Layer
      • Extension
      • Concurrency
      • Qualifier
      • Destination
  • Can be invoked:
    • Synchronously
      • Event Source Mapping (Lambda pull from services)
        • KDS
        • SQS and SQS FIFO
        • DynamoDB data streams
    • Asynchronously:
      • aws lambda invoke \ –function-name my-function \ –invocation-type Event \ –cli-binary-format raw-in-base64-out \ –payload ‘{ “key”: “value” }’ response.json
      • Uses an internal Event Queue
      • Can point to DLQ for failures.
      • AWS Services that are async:
        • S3
        • SNS
        • EventBridge
  • Lambda Destinations
    • For Event Source Mapping – For discarded events
    • For Async – Can replace DLQ
  • Lambda Container:
    • Base image must implement Lambda Runtime API
    • Can test locally through an emulator
  • Concurrency:
    • Reserved – ensure the max concurrency
    • Provisioned -prepares the no. of concurrent execution of a Lambda funciton.

SAM

  • An open-source framework that you can use to build serverless applications on AWS.
  • serverless application is a combination of Lambda functions, event sources, and other resources that work together to perform tasks. Note that a serverless application is more than just a Lambda function—it can include additional resources such as APIs, databases, and event source mappings.
  • Components:
    1. AWS SAM template specification
      • AWS SAM templates are an extension of AWS CloudFormation templates, with some additional components that make them easier to work with.
      • Written in YAML
      • Can specify other resources not just Lambda
    2. AWS SAM command-line interface (AWS SAM CLI).
      • sam build
      • aws cloudformation package / sam package
      • awas cloudformation deploy / sam deploy
  • Template Anatomy:
    • Transform declaration
      • Transform: AWS::Serverless-2016-10-31
      • Required
    • Globals section:
      • Globals
      •  Defines properties that are common to all your serverless functions and APIs
    • Resources section
      • can contain a combination of AWS CloudFormation resources and AWS SAM resources
      • Resources:
        • AWS::Serverless::Api – Creates a collection of Amazon API Gateway resources and methods that can be invoked through HTTPS endpoints
        • AWS::Serverless::Function – Creates an AWS Lambda function, an AWS Identity and Access Management (IAM) execution role, and event source mappings that trigger the function.
        • AWS::Serverless::SimpleTable – Creates a DynamoDB table with a single attribute primary key. It is useful when data only needs to be accessed via a primary key.
    • Parameters section
      • Objects that are declared in the Parameters section cause the sam deploy --guided command to present additional prompts to the user. 
  • Building
    • Gathers the build artifacts of your application’s dependencies and places them in the proper format and location for next steps, such as locally testing, packaging, and deploying.
    • CLI sam build
      • transform SAM template into CloudFormation template together with the application code
  • Testing
    • Can invoke your function locally
    • CLI sam local invoke command and providing its function logical ID and an event file
  • Packaging
    • Make application available for others to find and deploy
    • CLI aws cloudformation package / sam package
      • zip and upload to S3 bucket
  • Deploying
    • Can use CICD. For AWS use CodePipeline
    • CLI awas cloudformation deploy / sam deploy
      • Find the package from S3 and load to CloudFormation
    • Can use CodeDeploy
  • SAR
    • Repository for SAM
    • CLI: sam publish
  • Policy Templates:
    • S3ReadPolicy
    • SQSPollerPolicy
    • DyanmoDBCrudPolicy

Leave a Comment

Your email address will not be published. Required fields are marked *