夢のの*_*のの夢 4 amazon-web-services aws-lambda aws-api-gateway aws-cdk
我已经创建了一个在我的 aws 环境中调用的 lambda 函数add,我正在尝试构建一个 cdk 应用程序,它将生成一个新的 API Gateway,然后调用add.
我正在关注https://cdkworkshop.com/20-typescript/30-hello-cdk/300-apigw.html上的教程,我注意到我在网上遇到的所有示例似乎都以与以下类似的形式编写代码:
const hello = new lambda.Function(this, 'HelloHandler', {
runtime: lambda.Runtime.NODEJS_10_X, // execution environment
code: lambda.Code.fromAsset('lambda'), // code loaded from "lambda" directory
handler: 'hello.handler' // file is "hello", function is "handler"
});
const api = new apiGateWay.LambdaRestApi(this, 'api', {
handler: hello
})
Run Code Online (Sandbox Code Playgroud)
上面的例子直接创建了一个新的 lambda 函数名HelloHanlder。我想引用我之前创建的 function add,而不是向堆栈中添加任何新的 lambda 函数,大致如下:
const api = new apiGateWay.LambdaRestApi(this, 'api', {
handler: "add"
})
Run Code Online (Sandbox Code Playgroud)
这可以修复吗?
Bal*_*ala 11
选项 1:使用函数 Arn 中的现有 Lambda
const hello = lambda.Function.fromFunctionArn(
this,
"hello-lambda",
"arn:aws:lambda:us-east-1:111222233333:function:hello-lambda"
);
new apigw.LambdaRestApi(this, "Endpoint", {
handler: hello,
});
Run Code Online (Sandbox Code Playgroud)
选项 2:您可以将现有 lambda 导入到新的 CloudFormation 堆栈中,然后导出 Arn 并导入到 CDK 中
| 归档时间: |
|
| 查看次数: |
8875 次 |
| 最近记录: |