<?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>Modularity on {O}</title>
    <link>https://omarmakled.com/tags/modularity/</link>
    <description>Recent content in Modularity on {O}</description>
    <generator>Hugo -- 0.151.1</generator>
    <language>en-us</language>
    <atom:link href="https://omarmakled.com/tags/modularity/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>
  </channel>
</rss>
