'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? The code snippet looks like below. By the way I am using aws cdk version 2.24, which is the newer one. But when I run cdk synth, it gives me the Error: 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']
            }
        })
    }
}



Solution 1:[1]

The runtime you're defining in CDK will be the one used by your Lambda, which has nothing to do with you local environment.

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.

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).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zessx