<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bgoh216</title>
    <description>The latest articles on DEV Community by bgoh216 (@bgoh216).</description>
    <link>https://dev.to/bgoh216</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1419167%2F3d5f6ccc-68fc-4a9d-b2b1-898be0478017.jpg</url>
      <title>DEV Community: bgoh216</title>
      <link>https://dev.to/bgoh216</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bgoh216"/>
    <language>en</language>
    <item>
      <title>[CDKTF] Configuring API key source for API Gateway created with OpenAPI</title>
      <dc:creator>bgoh216</dc:creator>
      <pubDate>Fri, 12 Apr 2024 15:21:21 +0000</pubDate>
      <link>https://dev.to/bgoh216/cdktf-configuring-api-key-source-for-api-gateway-created-with-openapi-1h35</link>
      <guid>https://dev.to/bgoh216/cdktf-configuring-api-key-source-for-api-gateway-created-with-openapi-1h35</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;A typical &lt;strong&gt;ApiGatewayRestApi&lt;/strong&gt; object looks like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const apiGatewayRestApi = new aws.apiGatewayRestApi.ApiGatewayRestApi(this, "awpigw-rest-api", {
    name: "my-apigw",
    body: myOpenApiSpecification
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initial intuition and &lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-api-key-source.html" rel="noopener noreferrer"&gt;instruction&lt;/a&gt; to update API Gateway's API_KEY_SOURCE is to add &lt;code&gt;x-amazon-apigateway-api-key-source&lt;/code&gt; to OpenAPI specification and pass it as the body for initializing &lt;strong&gt;ApiGatewayRestApi&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Adding &lt;code&gt;x-amazon-apigateway-api-key-source&lt;/code&gt; to OpenAPI specification and setting it in the body does not update API Gateway's API_KEY_SOURCE&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "Test1"
  },
  "servers" : [ {
    "url" : "/{basePath}",
    "variables" : {
      "basePath" : {
        "default" : "import"
      }
    }
  } ],
  "x-amazon-apigateway-api-key-source" : "HEADER",
   .
   .
   .
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;In order to add the change the API Gateways's API_KEY_SOURCE, we only need to add one more line of configuration while initializing &lt;strong&gt;ApiGatewayRestApi&lt;/strong&gt;,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const apiGatewayRestApi = new aws.apiGatewayRestApi.ApiGatewayRestApi(this, "awpigw-rest-api", {
    name: "my-apigw",
    body: myOpenApiSpecification,
    apiKeySource: "AUTHORIZER"
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no need to configure it in the 'myOpenApiSpecification' as specified &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api#api_key_source" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cdktf</category>
      <category>apigw</category>
      <category>infrastructureascode</category>
    </item>
  </channel>
</rss>
