<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Api-Gateway on The Edge Cases</title>
    <link>https://www.kylestratis.com/tags/api-gateway/</link>
    <description>Recent content in Api-Gateway on The Edge Cases</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>© 2025</copyright>
    <lastBuildDate>Fri, 18 Sep 2026 22:04:36 -0400</lastBuildDate>
    <atom:link href="https://www.kylestratis.com/tags/api-gateway/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Raising Exceptions from Lambda to API Gateway Caller</title>
      <link>https://www.kylestratis.com/notes/raising-exceptions-from-lambda-to-api-gateway-caller/</link>
      <pubDate>Wed, 05 Oct 2022 17:09:29 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/raising-exceptions-from-lambda-to-api-gateway-caller/</guid>
      <description>&lt;p&gt;You can send exception feedback from a Lambda to an API Gateway API either by raising a Python exception and handling it via a mapping template, or return a specific set of values from the main handler function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;returning-from-the-handler-function&#34;&gt;Returning from the Handler Function&lt;/h2&gt;&#xA;&lt;p&gt;You can return a dictionary that includes at least:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the desired status code&lt;/li&gt;&#xA;&lt;li&gt;the message body (JSONified)&lt;/li&gt;&#xA;&lt;li&gt;and whether or not the body is base64 encoded&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&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-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; {  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;statusCode&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;404&lt;/span&gt;,  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;body&amp;#34;&lt;/span&gt;: simplejson&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dumps(  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;User &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;username&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; not found&amp;#34;&lt;/span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ),  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;isBase64Encoded&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;,  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;raising-an-exceptions&#34;&gt;Raising an Exceptions&lt;/h2&gt;&#xA;&lt;p&gt;Using a &lt;a href=&#34;https://aws.amazon.com/blogs/compute/error-handling-patterns-in-amazon-api-gateway-and-aws-lambda/&#34;&gt;mapping template&lt;/a&gt; allows you to simply use regex to associate an error message from a plain Python exception with a certain HTTP code. I don&amp;rsquo;t have any examples because I haven&amp;rsquo;t done it, preferring the &lt;a href=&#34;https://www.kylestratis.com/notes/raising-exceptions-from-lambda-to-api-gateway-caller/#returning-from-the-handler-function&#34;&gt;previous method&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>API Gateway URL Construction</title>
      <link>https://www.kylestratis.com/notes/api-gateway-url-construction/</link>
      <pubDate>Tue, 07 Jun 2022 16:39:00 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/api-gateway-url-construction/</guid>
      <description>&lt;p&gt;This is the construction of the base URL of an API Gateway API: &lt;code&gt;https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}/&lt;/code&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;sources&#34;&gt;Sources&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html&#34;&gt;AWS Docs - How to call API&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>AWS Lambda Return Values for API Triggering</title>
      <link>https://www.kylestratis.com/notes/aws-lambda-return-values-for-api-triggering/</link>
      <pubDate>Mon, 07 Feb 2022 21:41:05 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/aws-lambda-return-values-for-api-triggering/</guid>
      <description>&lt;p&gt;A Lambda triggered by an API has to return a dictionary with certain keys and values in order to not cause an error in execution (e.g. &amp;ldquo;malformed lambda proxy response&amp;rdquo;). These are the status code, body (JSONified), and if it&amp;rsquo;s base64 encoded. Headers can also be added to this structure, but they don&amp;rsquo;t seem required.&lt;/p&gt;&#xA;&lt;h2 id=&#34;code-example&#34;&gt;Code Example&lt;/h2&gt;&#xA;&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-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; {  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;statusCode&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;200&lt;/span&gt;,  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;body&amp;#34;&lt;/span&gt;: json&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dumps(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;User &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;username&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; not found&amp;#34;&lt;/span&gt;),  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;isBase64Encoded&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;sources&#34;&gt;Sources&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/&#34;&gt;https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.onlinetutorialspoint.com/aws/fixed-malformed-lambda-proxy-response-status-502.html&#34;&gt;https://www.onlinetutorialspoint.com/aws/fixed-malformed-lambda-proxy-response-status-502.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>AWS API Gateway Changes Break Deployment</title>
      <link>https://www.kylestratis.com/notes/aws-api-gateway-changes-break-deployment/</link>
      <pubDate>Mon, 07 Feb 2022 15:43:47 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/aws-api-gateway-changes-break-deployment/</guid>
      <description>&lt;p&gt;If you try to rename a parameter in a deployed API Gateway object via CDK, deployment will break (you won&amp;rsquo;t be able to deploy the change). This seems to do with how CloudFormation diffs are applied, and it will cause a conflict during the deployment process (see &lt;a href=&#34;https://stackoverflow.com/questions/62346608/aws-lambda-rest-api-a-sibling-id-of-this-resource-already-has-a-variable-pa&#34;&gt;here&lt;/a&gt;). The workaround is to comment out all the API code in the CDK stack, deploy, then uncomment and redeploy. This removes and remakes the API.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
