<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>SAM on {O}</title>
    <link>https://omarmakled.com/tags/sam/</link>
    <description>Recent content in SAM on {O}</description>
    <generator>Hugo -- 0.151.1</generator>
    <language>en-us</language>
    <atom:link href="https://omarmakled.com/tags/sam/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Building a Practical Serverless API with SAM: Leveraging Nested Stacks for Organization</title>
      <link>https://omarmakled.com/posts/sam-nested/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-nested/</guid>
      <description>&lt;p&gt;This example demonstrates how to build and deploy a simple &lt;strong&gt;serverless API&lt;/strong&gt; using &lt;strong&gt;AWS Lambda&lt;/strong&gt;, &lt;strong&gt;API Gateway&lt;/strong&gt;, and &lt;strong&gt;AWS SAM&lt;/strong&gt; (Serverless Application Model). The core focus here is on leveraging &lt;strong&gt;modularity&lt;/strong&gt; and &lt;strong&gt;nested stacks&lt;/strong&gt; to create a well-organized and scalable project structure.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;project-structure&#34;&gt;Project Structure&lt;/h3&gt;
&lt;p&gt;Here&amp;rsquo;s a quick overview of the project&amp;rsquo;s key components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;api.yaml&lt;/code&gt;&lt;/strong&gt;: This SAM file defines the &lt;strong&gt;API Gateway&lt;/strong&gt;. It&amp;rsquo;s responsible for linking HTTP paths (like &lt;code&gt;/orders&lt;/code&gt; and &lt;code&gt;/logs&lt;/code&gt;) to the appropriate Lambda Functions. Crucially, it imports the API definition from &lt;code&gt;openapi.yaml&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;log.yaml&lt;/code&gt;&lt;/strong&gt;: This SAM file contains the definition for the &lt;strong&gt;Lambda Function&lt;/strong&gt; responsible for fetching logs (&lt;code&gt;GetLogs&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;order.yaml&lt;/code&gt;&lt;/strong&gt;: This SAM file contains the definition for the &lt;strong&gt;Lambda Function&lt;/strong&gt; responsible for fetching orders (&lt;code&gt;GetOrders&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;openapi.yaml&lt;/code&gt;&lt;/strong&gt;: This is the &lt;strong&gt;OpenAPI (Swagger) file&lt;/strong&gt; that specifies the API paths (e.g., &lt;code&gt;/orders&lt;/code&gt;, &lt;code&gt;/logs&lt;/code&gt;) and how they integrate with the Lambda Functions. Here, we define the &lt;code&gt;x-amazon-apigateway-integration&lt;/code&gt; that links each path to the ARN of the relevant Lambda Function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;template.yaml&lt;/code&gt;&lt;/strong&gt;: This is the &lt;strong&gt;main SAM template&lt;/strong&gt; for your project. It acts as an orchestrator for all the sub-stacks (&lt;code&gt;OrderStack&lt;/code&gt;, &lt;code&gt;LogStack&lt;/code&gt;, &lt;code&gt;ApiStack&lt;/code&gt;). Each sub-stack points to its respective YAML file using the &lt;code&gt;Location&lt;/code&gt; property of &lt;code&gt;AWS::Serverless::Application&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;why-modularity-and-nested-stacks&#34;&gt;Why Modularity and Nested Stacks?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Modularity &amp;amp; Organization:&lt;/strong&gt;  When you split your project into separate files like &lt;code&gt;order.yaml&lt;/code&gt;, &lt;code&gt;log.yaml&lt;/code&gt;, and &lt;code&gt;api.yaml&lt;/code&gt;, your project becomes easier to organize and understand. Each file focuses on one part of the app, so it&amp;rsquo;s easier to work on and update, especially when the project gets bigger.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Build a Simple API on AWS with Lambda, API Gateway, and SAM</title>
      <link>https://omarmakled.com/posts/lambda-api-sam/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/lambda-api-sam/</guid>
      <description>&lt;p&gt;This example shows how to build and deploy a simple &lt;strong&gt;serverless API&lt;/strong&gt; using &lt;strong&gt;AWS Lambda&lt;/strong&gt;, &lt;strong&gt;API Gateway&lt;/strong&gt;, and &lt;strong&gt;AWS SAM&lt;/strong&gt; (Serverless Application Model). The API fetches a list of todos from a public endpoint and returns them via an HTTP GET request.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;project-structure&#34;&gt;Project Structure&lt;/h3&gt;
&lt;p&gt;Here&amp;rsquo;s a quick overview of the project&amp;rsquo;s key components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;functions/&lt;/code&gt;&lt;/strong&gt;: Contains the Lambda function &lt;code&gt;ListTodos.mjs&lt;/code&gt;, which fetches todo items from a public API using Axios.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tests/&lt;/code&gt;&lt;/strong&gt;: Contains a Jest test to ensure the function returns items with a 200 status code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;layers/&lt;/code&gt;&lt;/strong&gt;: Optional shared layer for common dependencies (e.g., axios), defined under &lt;code&gt;nodejs/package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;template.yaml&lt;/code&gt;&lt;/strong&gt;: AWS SAM template that defines the infrastructure:
&lt;ul&gt;
&lt;li&gt;Lambda function (&lt;code&gt;ListTodosFunction&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;API Gateway (&lt;code&gt;/posts&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Shared Layer&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&#34;how-it-works&#34;&gt;How It Works&lt;/h3&gt;
&lt;p&gt;When a client makes a &lt;code&gt;GET&lt;/code&gt; request to &lt;code&gt;/todos&lt;/code&gt;, the Lambda function is triggered, fetches data from &lt;code&gt;https://jsonplaceholder.typicode.com/todos?_limit=3&lt;/code&gt;, and returns it as JSON.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Serverless Messaging with AWS SAM: SNS, SQS, and Lambda</title>
      <link>https://omarmakled.com/posts/sam-sns-sqs/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-sns-sqs/</guid>
      <description>&lt;p&gt;This example shows how to build a &lt;strong&gt;serverless messaging pipeline&lt;/strong&gt; using &lt;strong&gt;AWS SAM&lt;/strong&gt;. The project uses &lt;strong&gt;SNS&lt;/strong&gt; to publish messages, &lt;strong&gt;SQS&lt;/strong&gt; queues to separate concerns, and &lt;strong&gt;Lambda functions&lt;/strong&gt; to process the data. It also uses &lt;strong&gt;filter policies&lt;/strong&gt; to control message delivery to each queue.&lt;/p&gt;
&lt;p&gt;This architecture is useful when you want to send different types of data to different consumers, and keep your application components decoupled.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;project-structure&#34;&gt;Project Structure&lt;/h3&gt;
&lt;p&gt;The template defines:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Organize AWS Lambda Projects with Nested Stacks and Layers in SAM</title>
      <link>https://omarmakled.com/posts/sam-layer/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-layer/</guid>
      <description>&lt;p&gt;This example shows how to build a &lt;strong&gt;modular AWS Lambda project&lt;/strong&gt; using &lt;strong&gt;SAM (Serverless Application Model)&lt;/strong&gt; with &lt;strong&gt;nested stacks&lt;/strong&gt; and a &lt;strong&gt;shared layer&lt;/strong&gt;. This helps keep your project clean and organized by separating logic and shared dependencies.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;how-it-works&#34;&gt;How It Works&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;layer.yaml&lt;/code&gt;&lt;/strong&gt; creates a shared Lambda Layer that contains Node.js packages (like &lt;code&gt;axios&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;order.yaml&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;log.yaml&lt;/code&gt;&lt;/strong&gt; are two Lambda functions that use this shared layer.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;root template (&lt;code&gt;template.yaml&lt;/code&gt;)&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Creates the layer stack.&lt;/li&gt;
&lt;li&gt;Passes the layer reference to the other stacks as a parameter.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sam build
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sam deploy --guided
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Project Repository:&lt;/strong&gt; &lt;a href=&#34;https://github.com/OmarMakled/sam-nested-layer&#34;&gt;https://github.com/OmarMakled/sam-nested-layer&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>AWS SAM Nested Stacks for a Structured GraphQL API</title>
      <link>https://omarmakled.com/posts/sam-graphql/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-graphql/</guid>
      <description>&lt;p&gt;This example provides a structured approach to deploying a &lt;strong&gt;Serverless GraphQL API&lt;/strong&gt; using &lt;strong&gt;AWS Serverless Application Model (SAM)&lt;/strong&gt;, leveraging &lt;strong&gt;Nested Stacks&lt;/strong&gt; for modularity.&lt;/p&gt;
&lt;h3 id=&#34;project-structure-modular-stacks&#34;&gt;Project Structure: Modular Stacks&lt;/h3&gt;
&lt;p&gt;The core idea is to break down the infrastructure into specialized, manageable units using SAM&amp;rsquo;s Nested Stacks. This separation enhances clarity, reusability, and maintainability.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Root Template&lt;/strong&gt; acts as the orchestrator, defining the dependencies between the smaller stacks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;RolesStack&lt;/code&gt; (stacks/roles.yaml):&lt;/strong&gt; Creates the necessary &lt;strong&gt;IAM Roles&lt;/strong&gt; for Lambda execution and for AppSync to invoke the Lambda function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;GraphQLStack&lt;/code&gt; (stacks/graphql.yaml):&lt;/strong&gt; Provisions the &lt;strong&gt;AWS AppSync GraphQL API&lt;/strong&gt;, including the API itself, the API Key, and the Schema definition (which is assumed to be uploaded to an S3 location).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;FunctionsStack&lt;/code&gt; (stacks/functions.yaml):&lt;/strong&gt; Deploys the &lt;strong&gt;Lambda function&lt;/strong&gt;, the &lt;strong&gt;AppSync Data Source&lt;/strong&gt;, and the &lt;strong&gt;Resolvers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;query.graphql&lt;/code&gt;&lt;/strong&gt; the schema definition can also be split into smaller files (types, queries, and mutations). These fragments are then merged into a single final schema file (schema.graphql).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The best thing about this design is that everything is &lt;strong&gt;organized and independent&lt;/strong&gt;. Each group of functions or resources is in its own box (stack).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Organizing Serverless Code with AWS SAM: Lambda Layers and Testing with Jest</title>
      <link>https://omarmakled.com/posts/sam-jest/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-jest/</guid>
      <description>&lt;p&gt;This example demonstrates how to build &lt;strong&gt;clean, testable, and modular serverless applications&lt;/strong&gt; on AWS using &lt;strong&gt;AWS SAM&lt;/strong&gt;, &lt;strong&gt;Lambda Layers&lt;/strong&gt;, and &lt;strong&gt;Jest&lt;/strong&gt;. It focuses on two essential practices for scalable serverless development:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using &lt;strong&gt;Lambda Layers&lt;/strong&gt; to share code across functions&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;Jest&lt;/strong&gt; to properly test each function and its dependencies&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By combining these two patterns, you get a powerful structure that’s maintainable, reusable, and confidently testable.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;project-overview-shared-logic--layer-for-node-modules--testing&#34;&gt;Project Overview: Shared Logic + Layer for Node Modules + Testing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;functions/&lt;/code&gt;&lt;/strong&gt; – Your Lambda function handlers:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using Parameters vs. Export/Import in AWS SAM: What’s Better?</title>
      <link>https://omarmakled.com/posts/sam-import-vs-export/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://omarmakled.com/posts/sam-import-vs-export/</guid>
      <description>&lt;p&gt;When you build serverless applications with AWS SAM or CloudFormation, sometimes you need to &lt;strong&gt;share resources between stacks&lt;/strong&gt;. For example, you may have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Cognito User Pool&lt;/strong&gt; in one stack (for user authentication)&lt;/li&gt;
&lt;li&gt;And an &lt;strong&gt;API Gateway&lt;/strong&gt; in another stack that needs to use that Cognito pool&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are two main ways to connect these stacks:&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;option-1-using-parameters&#34;&gt;Option 1: Using Parameters&lt;/h2&gt;
&lt;p&gt;You can pass values like the &lt;strong&gt;User Pool ARN&lt;/strong&gt; or &lt;strong&gt;ID&lt;/strong&gt; as a parameter when you deploy the second stack.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
