attach lambda authorizer to http API

0

Hi team,

I want to create an API gw lambda authorizer and attach it to the HTTP API

this is the piece of code I did :

// create api gw authorizer
    const apiGwAuthorizer = new HttpLambdaAuthorizer(
      "ApiGwLambdaAuthorizer",
      myLambdaFuncAuth,
      {
        responseTypes: [HttpLambdaResponseType.SIMPLE], 
        identitySource: ["$request.header.my-header"],
        resultsCacheTtl: Duration.seconds(300),
      }
    );

    //attach the authorizer to the ANY route
    myhttpapi.addRoutes({
      integration: new HttpLambdaIntegration(
        "authorizer-lambda-integration",
        authorizerLambda
      ),
      path: "/ANY /{proxy+}",
      authorizer: apiGwAuthorizer ,
    });

but when I deploy the CDK this authorizer created but it's not associated with the API GW

the API GW is passed as parameter from other stack in this stack

Not sure what I miss here, is it because the route 'ANY /{proxy+}' already exists?

1回答
0

Not sure, but try doing it the other way around (if you want to split into two stacks). Create the Lambda function in one stack. In the API GW stack, attach the authorizer to the right routes.

profile pictureAWS
エキスパート
Uri
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ