简体   繁体   中英

Is there a way to connect a new AWS ApiGateway to existing lambda funtion using AWS-CDK? (TypeScript)

I am new to AWS CDK. I am trying to create a API gateway, and connect it to the AWS lambda. But I want these 2 modules to be separate code structures.

I created the lambda functions and the API gateway in 2 different projects. And my AWS console has both API and lambda init. But I am not sure how to connect my API gateway to these lambdas.

The only way I could find was

    new lambda.Function(this, 'createPr', {
      code: lambda.Code.asset("resources/lambdas"),
      ....
      ....
    });

But this required the directory structure pointing towards lambda code.

Any help would be much appreciated!

You can import the other lambda function from ARN

const otherFunction = lambda.Function.fromFunctionArn(this, 'otherfunction', cdk.Fn.importValue("otherstack-function-arn"))

The cdk.Fn.importValue allow you to import value from other cloudformation script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM