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.
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",
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With