简体   繁体   English

本地节点版本会影响 aws 的 cdk 命令吗?

[英]Does local node version affect the cdk command for aws?

I was wondering if I have node version 16 on my computer and if I develop my aws lambda locally with cdk and specified the runtime as NODEJS_14, will it still work?我想知道我的计算机上是否有节点版本 16,如果我使用 cdk 在本地开发我的 aws lambda 并将运行时指定为 NODEJS_14,它还能工作吗? The code snippet looks like below.代码片段如下所示。 By the way I am using aws cdk version 2.24, which is the newer one.顺便说一句,我使用的是 aws cdk 版本 2.24,它是较新的版本。 But when I run cdk synth, it gives me the Error: spawnSync docker ENOENT.但是当我运行 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']
            }
        })
    }
}

The runtime you're defining in CDK will be the one used by your Lambda, which has nothing to do with you local environment.您在 CDK 中定义的运行时将是您的 Lambda 使用的运行时,与您的本地环境无关。

So yes, technically this will work, but you'd better use the same Node version to test your code (you can use tools like nvm to manage multiple Node versions locally) if you don't want unexpected failures caused by this version difference.所以是的,从技术上讲这会起作用,但是如果您不希望由此版本差异导致意外失败,您最好使用相同的 Node 版本来测试您的代码(您可以使用nvm 之类的工具在本地管理多个 Node 版本)。

Additionally, you won't be able to run TypeScript code with the NODEJS_14_X runtime, you'll have to first transpile your code in JavaScript (more information in AWS documentation on this topic).此外,您将无法使用NODEJS_14_X运行时运行 TypeScript 代码,您必须首先在 JavaScript 中转译您的代码(有关此主题的AWS 文档中的更多信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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