4

In our project we are using AwsCustomResource:

    const sdkCall: customResource.AwsSdkCall = {
         service: 'KMS',
         action: 'replicateKey',
         physicalResourceId: cr.PhysicalResourceId.of('CustomResource::KeyReplicaCreation'),
         parameters: {
           KeyId: keyId,
           ReplicaRegion: replicaRegion
         }
       };
    new cr.AwsCustomResource(this, `example replica`, {
      onCreate: sdkCall,
      onUpdate: sdkCall,
      policy: cr.AwsCustomResourcePolicy.fromStatements([
        new iam.PolicyStatement({
          effect: iam.Effect.ALLOW,
          actions: ['kms:*'],
          resources: ['*']
        })
      ])
    });

Now that we know that nodejs12.x is not supported where can we provide the lambda runtime value?

We have checked the props and there is no way to provide it.

elbik
  • 1,749
  • 2
  • 16
  • 21
dead_webdev
  • 164
  • 2
  • 9

3 Answers3

2

Custom Resource handlers were upgraded from NodeJS 12 back in CDK 2.28

Here is the relevant PR: https://github.com/aws/aws-cdk/pull/20595

gshpychka
  • 8,523
  • 1
  • 11
  • 31
1

As @gshpychka suggested, you need to upgrade CDK for that. AWS announced end of support for node.js 12.x last May.

The API for AwsCustomResource doesn't let you pick the node.js runtime version.

It was upgraded from 14.x to 16.x with PR #24916 in version 2.77.

It was upgraded from 12.x to 14.x with PR #20595 in version 2.28

You can theoretically override the runtime version using an escape hatch, but I don't know if it will actually work. The Lambda code itself might not be ready to run on newer versions of node.js. But you can try with:

import * as cdk from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';

// find SingletonLambda for AwsCustomResource
const providerFunctionL2 = cdk.Stack.of(invite).node.findChild('AWS679f53fac002430cb0da5b7982bd2287') as lambda.Function;
// get CfnFunction
const providerFunctionL1 = providerFunctionL2.node.defaultChild as lambda.CfnFunction;
// override runtime
providerFunctionL1.addPropertyOverride('Runtime', lambda.Runtime.NODEJS_16_X.name);

Make sure to use that code after you've already used AwsCustomResource at least once.

kichik
  • 33,220
  • 7
  • 94
  • 114
-1

I was facing similar issue on may lambda stack using CDK. Upgrading cdk versions resolved the issue:

Following is the list packages that I upgraded:

"@types/node": "^20.3.2", "aws-cdk": "^2.85.0", "ts-node": "^10.9.1", "aws-cdk-lib": "^2.85.0", "cdk": "^2.85.0",

Sushil
  • 1