Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding integration response to AWS websocket API with @aws-cdk/aws-apigatewayv2

Is there a way to add an integration response to the AWS WebSocket API using AWS CDK with the aws-apigatewayv2 package? This answer shows a great way to achieve just that using CloudFormation. But I haven't been able to translate it into the AWS CDK. Thanks!

EDIT:

Sorry, I should have clarified how I am trying to add the integration response now:

  const webSocketApi = new WebSocketApi(this, 'Api', {
    defaultRouteOptions: {
      integration: new LambdaWebSocketIntegration({ handler: lambdaFn }),
    },
  })
  new CfnIntegrationResponse(this, 'response', {
    apiId: webSocketApi.apiId,
    integrationId: /* ? */,
    integrationResponseKey: '$default',
  })
  const stage = new WebSocketStage(this, 'Stage', {
    webSocketApi,
    stageName: 'dev',
    autoDeploy: true,
  })

I could add the integration response using CfnIntegrationResponse but I don't have a way to access the integration id of the LambdaWebSocketIntegration.

like image 783
Martin Šťáva Avatar asked Nov 14 '22 18:11

Martin Šťáva


1 Answers

The solution is to use CfnRouteResponse instead of CfnIntegrationResponse, like this:

const api = new WebSocketApi(...)
const route = api.addRoute(...)

new apigateway.CfnRouteResponse(this, "wsRouteResponse", {
    apiId: api.apiId,
    routeId: route.routeId,
    routeResponseKey: "$default",
});
like image 190
yeahwhat Avatar answered Dec 25 '22 10:12

yeahwhat