{"id":660,"date":"2022-03-28T01:58:57","date_gmt":"2022-03-28T01:58:57","guid":{"rendered":"https:\/\/192.168.1.3\/wordpress\/?p=660"},"modified":"2025-07-03T10:36:33","modified_gmt":"2025-07-03T10:36:33","slug":"aws-developer-associate-dva-c01-review-material-lambda-and-sam","status":"publish","type":"post","link":"https:\/\/mylinuxsite.com\/wordpress\/?p=660","title":{"rendered":"AWS Developer Associate (DVA-C01) Review Material \u2013 Lambda and SAM"},"content":{"rendered":"\n<!--more continue reading-->\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Lambda<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>General<\/strong><ul><li>A compute service that lets you run code without provisioning or managing servers.<\/li><li>Best suited for shorter, event-driven workloads, since Lambda functions run for up to 15 minutes per invocation.<\/li><li><strong>Concepts<\/strong>:<ul><li>Function<\/li><li>Trigger<\/li><li>Event<\/li><li>Execution environment<\/li><li>Instruction set architecture<\/li><li>Deployment package<\/li><li>Runtime<\/li><li>Layer<\/li><li>Extension<\/li><li>Concurrency<\/li><li>Qualifier<\/li><li>Destination<\/li><\/ul><\/li><\/ul><\/li><li>Can be invoked:<ul><li>Synchronously<ul><li><strong>Event Source Mapping <\/strong>(Lambda pull from services)<ul><li>KDS<\/li><li>SQS and SQS FIFO<\/li><li>DynamoDB data streams<\/li><\/ul><\/li><\/ul><\/li><li>Asynchronously:<ul><li>aws lambda invoke \\ &#8211;function-name my-function \\ <strong>&#8211;invocation-type Event <\/strong>\\ &#8211;cli-binary-format raw-in-base64-out \\ &#8211;payload &#8216;{ &#8220;key&#8221;: &#8220;value&#8221; }&#8217; response.json<\/li><li>Uses an internal <strong>Event Queue<\/strong><\/li><li>Can point to DLQ for failures.<\/li><li>AWS Services that are async:<ul><li>S3<\/li><li>SNS<\/li><li>EventBridge<\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li>Lambda Destinations<ul><li>For Event Source Mapping &#8211; For discarded events<\/li><\/ul><ul><li>For Async &#8211; Can replace DLQ<\/li><\/ul><\/li><li>Lambda Container:<ul><li>Base image must implement Lambda Runtime API<\/li><li>Can test locally through an emulator<\/li><\/ul><\/li><li>Concurrency:<ul><li>Reserved &#8211; ensure the max concurrency.  Useful if you don&#8217;t want other functions taking up all the available unreserved concurrency<\/li><li>Provisioned &#8211; the no. of pre-initialised Lambda functions. Useful for reducing cold start latencies.<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>SAM<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>An open-source framework that you can use to build&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/aws.amazon.com\/serverless\/\" target=\"_blank\">serverless applications<\/a>&nbsp;on AWS.<\/li><li>A&nbsp;<strong>serverless application<\/strong>&nbsp;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\u2014it can include additional resources such as APIs, databases, and event source mappings.<\/li><li><strong>Components<\/strong>:<ol><li><strong>AWS SAM template specification<\/strong><ul><li>AWS SAM templates are an<strong> extension of AWS CloudFormation templates<\/strong>, with some additional components that make them easier to work with.<\/li><li>Written in YAML<\/li><li>Can specify other resources not just Lambda<\/li><\/ul><\/li><li><strong>AWS SAM command-line interface (AWS SAM CLI)<\/strong>.<ul><li>sam build<\/li><li>aws cloudformation package \/ sam package<\/li><li>awas cloudformation deploy \/ sam deploy<\/li><\/ul><\/li><\/ol><\/li><li><strong>Template Anatomy:<\/strong><ul><li><strong>Transform declaration<\/strong><ul><li><strong><em>Transform: AWS::Serverless-2016-10-31<\/em><\/strong><\/li><li>Required<\/li><\/ul><\/li><li><strong>Globals section<\/strong>:<ul><li><strong><em>Globals<\/em><\/strong><\/li><li>&nbsp;Defines properties that are common to all your serverless functions and APIs<\/li><\/ul><\/li><li><strong>Resources section<\/strong><ul><li>can contain a combination of AWS CloudFormation resources and AWS SAM resources<\/li><li>Resources:<ul><li><strong>AWS::Serverless::Api<\/strong> &#8211; Creates a collection of Amazon API Gateway resources and methods that can be invoked through HTTPS endpoints<\/li><li><strong>AWS::Serverless::Function <\/strong>&#8211; Creates an AWS Lambda function, an AWS Identity and Access Management (IAM) execution role, and event source mappings that trigger the function.<\/li><li><strong>AWS::Serverless::SimpleTable<\/strong> &#8211; Creates a DynamoDB table with a single attribute primary key. It is useful when data only needs to be accessed via a primary key.<\/li><\/ul><\/li><\/ul><\/li><li><strong>Parameters section<\/strong><ul><li>Objects that are declared in the&nbsp;<code>Parameters<\/code>&nbsp;section cause the&nbsp;<code>sam deploy --guided<\/code>&nbsp;command to present additional prompts to the user.&nbsp;<\/li><\/ul><\/li><\/ul><\/li><li><strong>Building<\/strong><ul><li>Gathers the build artifacts of your application&#8217;s dependencies and places them in the proper format and location for next steps, such as locally testing, packaging, and deploying.<\/li><li>CLI <strong><em>sam build<\/em><\/strong><ul><li>transform SAM template into CloudFormation template together with the application code<\/li><\/ul><\/li><\/ul><\/li><li><strong>Testing<\/strong><ul><li>Can invoke your function locally<\/li><li>CLI <strong>sam local invoke<\/strong>&nbsp;command and providing its function logical ID and an event file<\/li><\/ul><\/li><li><strong>Packaging<\/strong><ul><li>Make application available for others to find and deploy<\/li><li>CLI <strong><em>aws cloudformation package \/ sam package <\/em><\/strong><ul><li>zip and upload to S3 bucket<\/li><\/ul><\/li><\/ul><\/li><li><strong>Deploying<\/strong><ul><li>Can use CICD. For AWS use CodePipeline <\/li><li>CLI <strong>awas cloudformation deploy \/ sam deploy<\/strong><ul><li>Find the package from S3 and load to CloudFormation<\/li><\/ul><\/li><li>Can use <strong>CodeDeploy<\/strong><\/li><\/ul><\/li><li><strong>SAR<\/strong><ul><li>Repository for SAM<\/li><li>CLI: <strong>sam publish<\/strong><\/li><\/ul><\/li><li><strong>Policy Templates:<\/strong><ul><li>S3ReadPolicy<\/li><li>SQSPollerPolicy<\/li><li>DyanmoDBCrudPolicy<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[11],"tags":[],"class_list":["post-660","post","type-post","status-publish","format-standard","hentry","category-aws-review-notes"],"_links":{"self":[{"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=660"}],"version-history":[{"count":15,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":1567,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/660\/revisions\/1567"}],"wp:attachment":[{"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mylinuxsite.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}