Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

‼️ 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... #13620

Closed
yurynix opened this issue Mar 16, 2021 · 6 comments · Fixed by #13624
Assignees
Labels
@aws-cdk/aws-lambda-event-sources @aws-cdk/aws-s3-notifications @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. management/tracking Issues that track a subject or multiple issues p0

Comments

@yurynix
Copy link

yurynix commented Mar 16, 2021

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.

const resource = new InLineLambda(this, 'Resource', {
type: resourceType,
properties: {
Description: 'AWS CloudFormation handler for "Custom::S3BucketNotifications" resources (@aws-cdk/aws-s3)',
Code: { ZipFile: `exports.handler = ${handler.toString()};` },

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

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

@yurynix yurynix added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 16, 2021
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Mar 16, 2021
@christophgysin
Copy link
Contributor

Seems to be related to aws-cloudformation/cloudformation-coverage-roadmap#80

@iliapolo
Copy link
Contributor

@yurynix Thanks for reporting this. We are looking into it.

@iliapolo
Copy link
Contributor

Yeap, confirmed.

Until we release a patch, you can use the following workaround:

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

Apologies for this.

@iliapolo iliapolo added the p0 label Mar 16, 2021
@iliapolo iliapolo changed the title (aws-s3): ZipFile can only be used when Runtime is NOT nodejs14.x ‼️ 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... Mar 16, 2021
@iliapolo iliapolo pinned this issue Mar 16, 2021
@iliapolo iliapolo added management/tracking Issues that track a subject or multiple issues @aws-cdk/aws-lambda-event-sources and removed needs-triage This issue or PR still needs to be triaged. labels Mar 16, 2021
@mergify mergify bot closed this as completed in #13624 Mar 16, 2021
mergify bot pushed a commit that referenced this issue Mar 16, 2021
#13624)

This [PR](#13488) upgraded our Node runtimes from `10` to `14`. The problem is that Node14 isn't supported for lambda functions using inline code (i.e `ZipFile`). 

Change to Node12 specifically for the notification handler since it's the only one using `InlineLambda`. 

Fixes #13620

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

iliapolo added a commit that referenced this issue Mar 16, 2021
#13624)

This [PR](#13488) upgraded our Node runtimes from `10` to `14`. The problem is that Node14 isn't supported for lambda functions using inline code (i.e `ZipFile`). 

Change to Node12 specifically for the notification handler since it's the only one using `InlineLambda`. 

Fixes #13620

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@iliapolo
Copy link
Contributor

A patch has been released: https://github.com/aws/aws-cdk/releases/tag/v1.94.1

@yurynix
Copy link
Author

yurynix commented Mar 17, 2021

Thank you for the quick turnaround 🙂

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Mar 17, 2021
aws#13624)

This [PR](aws#13488) upgraded our Node runtimes from `10` to `14`. The problem is that Node14 isn't supported for lambda functions using inline code (i.e `ZipFile`). 

Change to Node12 specifically for the notification handler since it's the only one using `InlineLambda`. 

Fixes aws#13620

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Mar 18, 2021
aws#13624)

This [PR](aws#13488) upgraded our Node runtimes from `10` to `14`. The problem is that Node14 isn't supported for lambda functions using inline code (i.e `ZipFile`). 

Change to Node12 specifically for the notification handler since it's the only one using `InlineLambda`. 

Fixes aws#13620

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@iliapolo iliapolo unpinned this issue Mar 25, 2021
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
aws#13624)

This [PR](aws#13488) upgraded our Node runtimes from `10` to `14`. The problem is that Node14 isn't supported for lambda functions using inline code (i.e `ZipFile`). 

Change to Node12 specifically for the notification handler since it's the only one using `InlineLambda`. 

Fixes aws#13620

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-event-sources @aws-cdk/aws-s3-notifications @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants