-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(lambda): Validate Lambda "functionName" parameter #17970
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9acbd96
feat: Validate Lambda "functionName" parameter
Dzhuneyt 313ef87
Merge branch 'master' into dzhuneyt/issue-13264
Dzhuneyt 684f44a
chore: Apply suggestions from code review
Dzhuneyt 2330799
chore: Address code review comments
Dzhuneyt 242d8e4
Merge branch 'master' into dzhuneyt/issue-13264
Dzhuneyt 7a1cab6
Merge branch 'master' into dzhuneyt/issue-13264
Dzhuneyt f9d48eb
pr feedback and refactoring
kaizencc 50b31f2
Merge branch 'master' into dzhuneyt/issue-13264
kaizencc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import * as signer from '@aws-cdk/aws-signer'; | |
import * as sqs from '@aws-cdk/aws-sqs'; | ||
import { testDeprecated } from '@aws-cdk/cdk-build-tools'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Intrinsic, Token } from '@aws-cdk/core'; | ||
import * as constructs from 'constructs'; | ||
import * as _ from 'lodash'; | ||
import * as lambda from '../lib'; | ||
|
@@ -2278,6 +2279,45 @@ describe('function', () => { | |
}); | ||
expect(fn.architecture?.name).toEqual('arm64'); | ||
}); | ||
|
||
test('Error when function name is longer than 140 chars', () => { | ||
const stack = new cdk.Stack(); | ||
expect(() => new lambda.Function(stack, 'MyFunction', { | ||
code: lambda.Code.fromInline('foo'), | ||
runtime: lambda.Runtime.NODEJS_12_X, | ||
handler: 'index.handler', | ||
functionName: 'a'.repeat(141), | ||
})).toThrow(/Function name can not be longer than 140 characters./); | ||
}); | ||
|
||
test('Error when function name contains invalid characters', () => { | ||
const stack = new cdk.Stack(); | ||
[' ', '\n', '\r', '[', ']', '<', '>', '$'].forEach(invalidChar => { | ||
expect(() => { | ||
new lambda.Function(stack, `foo${invalidChar}`, { | ||
code: new lambda.InlineCode('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this runtime has an end-of-life set for 2/14/22. lets use Node 12 or 14. |
||
functionName: `foo${invalidChar}`, | ||
}); | ||
}).toThrow(/Function name can contain only letters, numbers, hyphens, or underscores with no spaces./); | ||
}); | ||
}); | ||
|
||
test('No error when function name is Tokenized and Unresolved', () => { | ||
const stack = new cdk.Stack(); | ||
expect(() => { | ||
const realFunctionName = 'a'.repeat(141); | ||
const tokenizedFunctionName = Token.asString(new Intrinsic(realFunctionName)); | ||
|
||
new lambda.Function(stack, 'foo', { | ||
code: new lambda.InlineCode('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too |
||
functionName: tokenizedFunctionName, | ||
}); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
|
||
function newTestLambda(scope: constructs.Construct) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this says that the length cannot be greater than 64 characters. Where are you gettintg the 140 from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps the 140 comes from here? @Dzhuneyt do you think you can help investigate the correct length here? #18795
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed that the number is 64 here. Going to update this PR accordingly.