From a014c30d5727afcc48706878dc4bf77a22bb122f Mon Sep 17 00:00:00 2001 From: seyeong Date: Wed, 15 Jun 2022 04:54:18 +1000 Subject: [PATCH] feat(lambda): inline function code can exceed 4096 bytes (#20624) CloudFormation removed the 4k charcaters limit for inline function code. Latest public documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile Historic documentation: https://web.archive.org/web/20220309033724/https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile Internal Code Review reference: CR-53662636 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-lambda/README.md | 2 +- packages/@aws-cdk/aws-lambda/lib/code.ts | 6 +----- packages/@aws-cdk/aws-lambda/test/code.test.ts | 12 ------------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/README.md b/packages/@aws-cdk/aws-lambda/README.md index 2453cd82abef8..9f186d471d173 100644 --- a/packages/@aws-cdk/aws-lambda/README.md +++ b/packages/@aws-cdk/aws-lambda/README.md @@ -29,7 +29,7 @@ runtime code. * `lambda.Code.fromBucket(bucket, key[, objectVersion])` - specify an S3 object that contains the archive of your runtime code. * `lambda.Code.fromInline(code)` - inline the handle code as a string. This is - limited to supported runtimes and the code cannot exceed 4KiB. + limited to supported runtimes. * `lambda.Code.fromAsset(path)` - specify a directory or a .zip file in the local filesystem which will be zipped and uploaded to S3 before deployment. See also [bundling asset code](#bundling-asset-code). diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index c5ae7f91d27bc..e8348d9da3c36 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -238,7 +238,7 @@ export class S3Code extends Code { } /** - * Lambda code from an inline string (limited to 4KiB). + * Lambda code from an inline string. */ export class InlineCode extends Code { public readonly isInline = true; @@ -249,10 +249,6 @@ export class InlineCode extends Code { if (code.length === 0) { throw new Error('Lambda inline code cannot be empty'); } - - if (code.length > 4096) { - throw new Error('Lambda source is too large, must be <= 4096 but is ' + code.length); - } } public bind(_scope: Construct): CodeConfig { diff --git a/packages/@aws-cdk/aws-lambda/test/code.test.ts b/packages/@aws-cdk/aws-lambda/test/code.test.ts index 4f16f9f8d0f0f..ed7767e488045 100644 --- a/packages/@aws-cdk/aws-lambda/test/code.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/code.test.ts @@ -14,10 +14,6 @@ describe('code', () => { expect(() => defineFunction(lambda.Code.fromInline('boom'), lambda.Runtime.GO_1_X)).toThrow(/Inline source not allowed for go1\.x/); expect(() => defineFunction(lambda.Code.fromInline('boom'), lambda.Runtime.JAVA_8)).toThrow(/Inline source not allowed for java8/); }); - test('fails if larger than 4096 bytes', () => { - expect(() => defineFunction(lambda.Code.fromInline(generateRandomString(4097)), lambda.Runtime.NODEJS_14_X)) - .toThrow(/Lambda source is too large, must be <= 4096 but is 4097/); - }); }); describe('lambda.Code.fromAsset', () => { @@ -525,11 +521,3 @@ function defineFunction(code: lambda.Code, runtime: lambda.Runtime = lambda.Runt runtime, }); } - -function generateRandomString(bytes: number) { - let s = ''; - for (let i = 0; i < bytes; ++i) { - s += String.fromCharCode(Math.round(Math.random() * 256)); - } - return s; -}