The API with ID [api-id] doesn’t include a route with path /* having an integration

0

I have Websocket API Gateway + Lambda setup using CDK. In the lambda function integration list I can see The API with ID [api-id] doesn’t include a route with path /* error.

Enter image description here

Here is the code I tried.

Enter image description here

I also tried it by removing like 159 but the result is same.

1 Antwort
0

if you are not already using latest CDK version, try to update it and see if it helps. I tried to replicate your issue, but I could not. Here's the code

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
// import * as sqs from 'aws-cdk-lib/aws-sqs';

export class WebsocketApiGwStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    //Node.js lambda function that prints hello. take code from JS file
    const hello = new cdk.aws_lambda.Function(this, 'hello', {
      runtime: cdk.aws_lambda.Runtime.NODEJS_LATEST,
      code: cdk.aws_lambda.Code.fromAsset('lambda/hello'),
      handler: 'hello.handler',
    });

    //API Gateway websocket API
    const api = new cdk.aws_apigatewayv2.WebSocketApi(this, 'api', {
      connectRouteOptions: { integration: new cdk.aws_apigatewayv2_integrations.WebSocketLambdaIntegration('connect', hello) },
      disconnectRouteOptions: { integration: new cdk.aws_apigatewayv2_integrations.WebSocketLambdaIntegration('disconnect', hello) },
    });

    //add a new stage to api
    const stage = new cdk.aws_apigatewayv2.WebSocketStage(this, 'stage', {
      webSocketApi: api,
      stageName: 'dev',
    });

    //format arn
    const arn = cdk.Stack.of(this).formatArn({
      service: 'execute-api',
      resource: `${stage.stageName}/POST/*`,
      resourceName: api.apiId
    });

    //add to lambda role policy
    hello.addToRolePolicy(new cdk.aws_iam.PolicyStatement({
      actions: ['execute-api:ManageConnections'],
      resources: [arn]
    }));
    
    api.grantManageConnections(hello)

  }
}

AWS
beantwortet vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen