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 Answer
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
answered 18 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions