DEV Community

bgoh216
bgoh216

Posted on

[CDKTF] Configuring API key source for API Gateway created with OpenAPI

Context

A typical ApiGatewayRestApi object looks like this,

const apiGatewayRestApi = new aws.apiGatewayRestApi.ApiGatewayRestApi(this, "awpigw-rest-api", {
    name: "my-apigw",
    body: myOpenApiSpecification
})
Enter fullscreen mode Exit fullscreen mode

Initial intuition and instruction to update API Gateway's API_KEY_SOURCE is to add x-amazon-apigateway-api-key-source to OpenAPI specification and pass it as the body for initializing ApiGatewayRestApi.

Problem

Adding x-amazon-apigateway-api-key-source to OpenAPI specification and setting it in the body does not update API Gateway's API_KEY_SOURCE

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "Test1"
  },
  "servers" : [ {
    "url" : "/{basePath}",
    "variables" : {
      "basePath" : {
        "default" : "import"
      }
    }
  } ],
  "x-amazon-apigateway-api-key-source" : "HEADER",
   .
   .
   .
}
Enter fullscreen mode Exit fullscreen mode

Solution

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 ApiGatewayRestApi,

const apiGatewayRestApi = new aws.apiGatewayRestApi.ApiGatewayRestApi(this, "awpigw-rest-api", {
    name: "my-apigw",
    body: myOpenApiSpecification,
    apiKeySource: "AUTHORIZER"
})
Enter fullscreen mode Exit fullscreen mode

There is no need to configure it in the 'myOpenApiSpecification' as specified here.

Top comments (0)