Search code examples
amazon-web-servicesamazon-s3aws-lambdaamazon-sns

BucketNotificationsHandler failing for lambda version but no lambda in CDK code


I am trying to create a CloudFormation stack via CDK. I am creating a S3 bucket and listening its create notifications to a SNS.

But my CloudfFormation stack is failing with error:

The runtime parameter of nodejs10.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs14.x) while creating or updating functions.

BucketNotificationsHandlerXXXXXXX

Resource handler returned message: "The runtime parameter of nodejs10.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs14.x) while creating or updating functions. (Service: Lambda, Status Code: 400, Request ID: XXXXXX, Extended Request ID: null)" (RequestToken: XXXXXXX, HandlerErrorCode: InvalidRequest)

I am not sure from where this lambda error is coming into picture. And how can change its version, as I am not using lambda in this CDK.

Code part which am using in CDK:

    const snsOutput = new sns.Topic(this, 'snsOutput',
                {topicName: `snsOutput`});  // sns creation

    const S3Output = new Bucket(this, "S3Output", {
                    bucketName: `S3Output`,
                    blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
                    lifecycleRules: [{ expiration: Duration.days(3) }],
                    removalPolicy: RemovalPolicy.DESTROY,
                });  // s3 creation
    // creating event for s3 to sns
    S3Output.addObjectCreatedNotification(new s3n.SnsDestination(snsOutput)); 
   

Solution

  • Short summary on who is creating this Lambda function?

    It is used internally by CDK to apply configuration notifications on the bucket. Its a custom resource that run s3.putNotificationConfiguration on the bucket. You can read on this in a bit more details in this link


    Now all being said, There are two ways to fix this issue:

    1. Update your aws-cdk version to anything above ^1.94.1. A fix has already been released for this. Caution: this may not be as easy as it seems. With tons of coupling with constructs package, you might face difficult is resolving the cynth failures.
    2. Alternatively, if you want to stick with your current version of cdk, you can opt for using escape hatches in CDK. Or simply add these lines of code and you would be good to go:
    const handler = Stack.of(this).node.tryFindChild('BucketNotificationsHandler050a0587b7544547bf325f094a3db834')?.node.defaultChild as cdk.CfnResource
    handler.addPropertyOverride("Runtime", "nodejs12.x");
    

    A little explanation on above code snippet: Using cdk escape hatch I am locating the logical id of lambda handler i.e BucketNotificationsHandler050a0587b7544547bf325f094a3db834 and then explictely overriding the Runtime value to be "nodejs12.x"


    I hope this would help resolve your issue.