【问题标题】:Does local node version affect the cdk command for aws?本地节点版本会影响 aws 的 cdk 命令吗?
【发布时间】:2022-08-24 17:39:10
【问题描述】:

我想知道我的计算机上是否有节点版本 16,如果我使用 cdk 在本地开发我的 aws lambda 并将运行时指定为 NODEJS_14,它还能工作吗?代码 sn-p 如下所示。顺便说一句,我使用的是 aws cdk 版本 2.24,它是较新的版本。但是当我运行 cdk synth 时,它给了我错误:spawnSync docker ENOENT。

import { aws_lambda_nodejs as lambda, aws_lambda as awslambda } from \"aws-cdk-lib\";
import { Runtime } from \"aws-cdk-lib/aws-lambda\";
import { Construct } from \'constructs\';
interface DocumentManagementAPIProps {
}

export class DocumentManagementAPI extends Construct {
    constructor(scope: Construct, id: string, props?: DocumentManagementAPIProps) {
        super(scope, id);
        const getDocumentsFunction = new lambda.NodejsFunction(this, \'getDocumentsFunction\', {
            runtime: awslambda.Runtime.NODEJS_14_X,
            entry: \'api/getDocuments/index.ts\',
            handler: \'getDocuments\',
            bundling: {
                externalModules: [\'aws-sdk\']
            }
        })
    }
}

    标签: node.js amazon-web-services aws-lambda aws-cdk


    【解决方案1】:

    您在 CDK 中定义的运行时将是您的 Lambda 使用的运行时,与您的本地环境无关。

    所以是的,从技术上讲这会起作用,但如果你不希望这个版本导致意外失败,你最好使用相同的 Node 版本来测试你的代码(你可以使用像 nvm 这样的工具在本地管理多个 Node 版本)区别。

    此外,您将无法使用 NODEJS_14_X 运行时运行 TypeScript 代码,您必须首先在 JavaScript 中转译您的代码(AWS documentation 中有关此主题的更多信息)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2013-10-01
      • 2021-03-07
      • 2020-04-28
      相关资源
      最近更新 更多