question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

‼️ NOTICE: S3 notifications fail to deploy on version 1.94.0 - ZipFile can only be used when Runtime is set to either of nodejs8.10...

See original GitHub issue

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Overview:

Users trying to configure s3 bucket notifications of any form will encounter a deployment failure. This includes:

  • bucket.addEventNotification
  • S3EventSource

These resources use a custom resource that is shipped with the CDK. The root cause is a recent upgrade we performed switching from the nodejs10.x runtime to nodejs14.x. CloudFormation does not support using nodejs14.x on lambda functions that use inline code (i.e ZipFile), which is indeed the case for this custom resource.

https://github.com/aws/aws-cdk/blob/e8f6267de8f0915fa950c301f2131efad494a87a/packages/%40aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts#L78-L82

Complete Error Message:

ZipFile can only be used when Runtime is set to either of nodejs8.10, nodejs10.x, nodejs12.x, python2.7, python3.6, python3.7, python3.8

Workaround:

The workaround is to use escape hatches and modify the runtime property:

const handler = Stack.of(this).node.tryFindChild('BucketNotificationsHandler050a0587b7544547bf325f094a3db834')?.node.defaultChild as cdk.CfnResource
handler.addPropertyOverride("Runtime", "nodejs12.x");

Solution:

Patch is available: https://github.com/aws/aws-cdk/releases/tag/v1.94.1

Related Issues:


Originally reported as

Deploying our existing CDK stack fails with 1.94.0 -> https://github.com/aws/aws-cdk/blob/a5be04270c2a372132964ab13d080a16f1a6f00c/packages/%40aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts#L85

...
 35/101 | 4:54:04 PM | UPDATE_FAILED        | AWS::Lambda::Function            | BucketNotificationsHandler050a0587b7544547bf325f094a3db834 (BucketNotificationsHandler050a0587b7544547bf325f094a3db8347ECC3691) ZipFile can only be used when Runtime is set to either of nodejs8.10, nodejs10.x, nodejs12.x, python2.7, python3.6, python3.7, python3.8.
	new NotificationsResourceHandler (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts:78:22)
	\_ Function.singleton (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts:39:16)
	\_ BucketNotifications.createResourceOnce (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts:107:55)
	\_ BucketNotifications.addNotification (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts:56:27)
	\_ Bucket.addEventNotification (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-s3/lib/bucket.ts:1459:24)
	\_ S3EventSource.bind (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-lambda-event-sources/lib/s3.ts:31:19)
	\_ Function.addEventSource (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/node_modules/@aws-cdk/aws-lambda/lib/function-base.ts:344:12)
	\_ new SnowmobileStackConstruct (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/lib/snowmobile-stack-construct.ts:236:20)
	\_ new Snowmobile (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/lib/Snowmobile.ts:16:18)
	\_ Object.<anonymous> (/home/deployer/.npm/_npx/2462/lib/node_modules/@wix/snowmobile-stack/bin/cdk-stack.ts:33:1)
	\_ Module._compile (internal/modules/cjs/loader.js:1063:30)
	\_ Module.m._compile (/home/deployer/.npm/_npx/2515/lib/node_modules/ts-node/src/index.ts:1056:23)
	\_ Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
	\_ Object.require.extensions.<computed> [as .ts] (/home/deployer/.npm/_npx/2515/lib/node_modules/ts-node/src/index.ts:1059:12)
	\_ Module.load (internal/modules/cjs/loader.js:928:32)
	\_ Function.Module._load (internal/modules/cjs/loader.js:769:14)
	\_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
	\_ main (/home/deployer/.npm/_npx/2515/lib/node_modules/ts-node/src/bin.ts:198:14)
	\_ Object.<anonymous> (/home/deployer/.npm/_npx/2515/lib/node_modules/ts-node/src/bin.ts:288:3)
	\_ Module._compile (internal/modules/cjs/loader.js:1063:30)
	\_ Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
	\_ Module.load (internal/modules/cjs/loader.js:928:32)
	\_ Function.Module._load (internal/modules/cjs/loader.js:769:14)
	\_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
	\_ /usr/local/lib/node_modules/npm/node_modules/libnpx/index.js:268:14

Reproduction Steps

Try to deploy a stack that has a lambda that triggered from an S3 bucket event, i.e.:

...
    someBucket.grantRead(someLambda);
    someLambda.addEventSource(
      new S3EventSource(someBucket, {
        events: [EventType.OBJECT_CREATED],
      }),
    );
...

What did you expect to happen?

The stack do be deployed =)

What actually happened?

The mentioned error.

Environment

  • CDK CLI Version :
  • Framework Version:
  • Node.js Version:
  • OS :
  • Language (Version):

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yurynixcommented, Mar 17, 2021

Thank you for the quick turnaround 🙂

1reaction
iliapolocommented, Mar 17, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-lambda/.jsii - UNPKG
In CDK by default, Lambda\nfunctions will use an autogenerated Role if one is ... code adds an S3 bucket notification as an event...
Read more >
What causes failures between iOS versions and existing strategies ...
1. What causes image discrepancies between snapshots from different iOS versions? 2. Will this be possible to include in a future release? 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found