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

feat(lambda): inline function code can exceed 4096 bytes #20624

Merged
merged 2 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 1 addition & 5 deletions packages/@aws-cdk/aws-lambda/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions packages/@aws-cdk/aws-lambda/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
}