这个问题的解决方案很多,但是其中一种是确保你的 Lambda 函数在您的 AWS 账户中存在,并且已在您的 CDK 代码中正确命名和引用。这里是一个例子:
const myFunction = new lambda.Function(this, 'MyFunction', {
functionName: 'my-function',
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset('path/to/code'),
handler: 'index.handler',
});
const api = new apigateway.RestApi(this, 'MyAPI');
const myResource = api.root.addResource('my-resource');
const integration = new apigateway.LambdaIntegration(myFunction);
myResource.addMethod('GET', integration);
在这个例子中,我们创建了一个 Lambda 函数“myFunction”,并将其添加到一个 API Gateway 资源中。我们使用“functionName”属性将函数命名为“my-function”。
确保您的 Lambda 函数名称与您在 CDK 代码中引用的名称保持一致,并且该函数存在于您的 AWS 账户中。如果函数不存在,请使用 CDK 将其创建并更新 CDK 代码。