【问题标题】:Trouble Specifying Handler for Api Gateway in AWS CDK在 AWS CDK 中为 Api 网关指定处理程序时遇到问题
【发布时间】:2021-07-02 08:38:46
【问题描述】:

我一直在学习有关 AWS CDK 的 Udemy 课程,我正在尝试创建一个 lambda 函数并将其与我的 api 网关集成相关联。我有以下代码:

    const getPhotos = new lambda.NodejsFunction(this, "MySimpleAppLambda", {
      runtime: Runtime.NODEJS_14_X,
      entry: path.join(__dirname, "..", "api", "get-photos", "index.ts"),
      handler: "getPhotos",
      environment: {
        PHOTO_BUCKET_NAME: bucket.bucketName
      }
    });

    // create lambda integration with api gateway
    const lambdaIntegration = new LambdaProxyIntegration({
      handler: getPhotos
    });

不幸的是,LambdaProxyIntegration 的处理程序属性需要一个 IFunction 实例,而 lambda.NodejsFunction 似乎不支持。调整以传递对 LambdaProxyIntegration 的正确引用的最佳方法是什么?

【问题讨论】:

    标签: typescript aws-lambda aws-cdk


    【解决方案1】:

    NodejsFunction 扩展了Function,实现了IFunction

    所以,我们可以将对象NodejsFunction 直接传递给处理程序。

    const lambdaIntegration = new LambdaProxyIntegration({
      handler: getPhotos
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-14
      • 2015-04-14
      • 1970-01-01
      • 2020-08-30
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多