0

I'm having issues finding examples on how to create "URL Query String Parameters" for "Integration Request" on API Gateway via Cloud Development Kit (CDK). Most examples I find are for lambda (I don't need this) not REST (I need this), and even those don't cover the integration requests.

I'm creating the api definition via aws-apigateway.SpecRestAPI.

const api = new apiGateway.SpecRestApi(this, 'my-api', {
      apiDefinition: apiGateway.ApiDefinition.fromInline(openApiDefinition),

I'm not sure I'm even tying the integration to the API.

How do I tie the integration to the API and how do I map the integration request like I can through the GUI?

I've tried exporting a manually configured API Gateway but it doesn't include any information about where to perform the translation.

Let me know if I need to add more information and thanks in advance!

fedonev
  • 20,327
  • 2
  • 25
  • 34
Damon Stamper
  • 378
  • 1
  • 4
  • 16

1 Answers1

1

If using ApiDefinition.fromInline then the request mapping goes in the OpenAPI file. See https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html and https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-requestParameters.html.

The "requestParameters" goes under the x-amazon-apigateway-integration node. If you don't know how to get an OpenAPI spec then create the API and integration like you normally would then export the file via https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-migrate-accounts-regions/

Also to map the integration to another AWS service (in my case SNS) I wasn't specifying the API object when instantiating the integration. Below is a working example of that.

const api = new apiGateway.SpecRestApi(this, 'my-api', {
      apiDefinition: apiGateway.ApiDefinition.fromInline(openApiDefinition)
)

const snsIntegration = new apiGateway.AwsIntegration(
  api,
  {
    proxy: false,
    service: "sns",
    action: "PutItem",
  }
);

Also if you run into issues with "Invalid mapping expression parameter specified" make sure you define the parameter in BOTH the method request AND the integration request.

A SUPER stripped down version of the OpenAPI file is below:

paths:
  /v1/contact:
    post:
      parameters:
        - name: "TopicArn"
          in: "query"
          required: true
          schema:
            type: "string"
      x-amazon-apigateway-integration:
        requestParameters : {
          integration.request.querystring.TopicArn : "method.request.header.TopicArn",
          integration.request.querystring.Message : "method.request.body",
        }
Damon Stamper
  • 378
  • 1
  • 4
  • 16