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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more