1

how can I deploy the following setting to my apigateway using cdk?

enter image description here

relevant part of my CDK-stack for my API:

....
const restApi = new apigateway.LambdaRestApi(this, "dyndns-api", {
  handler: dyndnsLambda,
  proxy: false,
  domainName: {
    securityPolicy: apigateway.SecurityPolicy.TLS_1_2,
    domainName: siteDomain,
    certificate: certificate,
    endpointType: apigateway.EndpointType.REGIONAL
  }
});

const methodResponse: apigateway.MethodResponse = {
  statusCode: "200", 
  responseModels: {"application/json": apigateway.Model.EMPTY_MODEL}
}

const integrationResponse: apigateway.IntegrationResponse = {
  statusCode: "200",
  contentHandling: apigateway.ContentHandling.CONVERT_TO_TEXT
}

new route53.ARecord(this, "apiDNS", {
  zone: zone,
  recordName: siteDomain,
  target: route53.RecordTarget.fromAlias(new route53Targets.ApiGateway(restApi)),
});

const requestTemplate = {
  "execution_mode" : "$input.params('mode')",
  "source_ip" : "$context.identity.sourceIp",
  "set_hostname" : "$input.params('hostname')",
  "validation_hash" : "$input.params('hash')"
}

const dnydnsIntegration = new apigateway.LambdaIntegration(dyndnsLambda, {
  allowTestInvoke: true,
  proxy: false,
  integrationResponses: [integrationResponse],
  passthroughBehavior: apigateway.PassthroughBehavior.WHEN_NO_TEMPLATES,
  requestTemplates: { "application/json": JSON.stringify(requestTemplate) },
});

restApi.root.addMethod("GET", dnydnsIntegration, {
  methodResponses: [methodResponse]
});

I know, that there is apigatewayv2.ApiMapping, but I have trouble implementing that into my stack. Also tried the deprecated class CfnApiMappingV2 with no success either.

globus243
  • 710
  • 1
  • 15
  • 31
  • Yes, `ApiMapping` is what you need. What issues are you having? – gshpychka Aug 17 '21 at 19:44
  • I was missing some kind of example and wasn't able to get to what I need purely from the (not really verbose) docs. Anyways, I noticed that I don't really need the mapping and decided to go without it. – globus243 Aug 22 '21 at 20:34
  • I'm also having troubles with aws_apigatewayv2 specifically on the domain_name option which i try to pass a DomainNameOptions object but fails. Any idea? – GeorgeGeorgitsis Oct 15 '21 at 10:42

0 Answers0