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

fix(synthetics): updated handler validation #26569

Merged
merged 5 commits into from
Aug 2, 2023
Merged

Conversation

lpizzinidev
Copy link
Contributor

This fix updates handler validation based on Synthetic rules for Node and Python runtimes.

Closes #26540.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 labels Jul 29, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team July 29, 2023 15:29
@github-actions github-actions bot added the star-contributor [Pilot] contributed between 25-49 PRs to the CDK label Jul 29, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@lpizzinidev
Copy link
Contributor Author

Exemption Request.
All validation cases should be covered by the unit tests.
Let me know if integration tests are needed.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jul 29, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on @lpizzinidev. One more thing: I think we should add a basic integ test that tests the folder/fileName.functionName scenario with a recent runtime just to make sure that the docs aren't wrong :) because sometimes they are.

Comment on lines 169 to 171
if (handler !== 'index.handler') {
throw new Error(`The handler for inline code must be "index.handler" (got "${handler}")`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about removing this. Have you tested this to make sure that it works? IIRC lambda will bundle inline code into an index.js|py file, which means that it should at least always start with index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restored the original code since I'm unsure about the expected behavior and couldn't find documentation about it.
Let me know if you think we should dive deeper into this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see anyone complaining about this, and it looks right to me. So lets keep it for now

Comment on lines 424 to 430
if (
runtime === Runtime.SYNTHETICS_PYTHON_SELENIUM_1_0 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_0 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_1 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_2 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_3
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (
runtime === Runtime.SYNTHETICS_PYTHON_SELENIUM_1_0 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_0 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_1 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_2 ||
runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_3
) {
const oldRuntimes = [/*put those runtimes here */];
if (oldRuntimes.includes(runtime)) {

Comment on lines 434 to 436
} else if (runtime === Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_4) {
if (!handler.match(/^[0-9A-Za-z_\\-]+\.[A-Za-z_][A-Za-z0-9_]*$/)) {
throw new Error(`Canary Handler must be specified either as \'fileName.handler\' or \'fileName.functionName\' for the \'syn-nodejs-puppeteer-3.4'\ runtime, received ${handler}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you get the info that 3.4 has it's own specific rule? From the cfn docs it seems this isn't the case:

For syn-python-selenium-1.1, syn-nodejs.puppeteer-3.4, and later runtimes, the handler can be specified as fileName.functionName , or you can specify a folder where canary scripts reside as folder/fileName.functionName .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I think I misread this line.
I'll apply the suggested changes and add the required tests.

}).toThrow(/Canary Handler must be specified either as 'fileName.handler' or 'fileName.functionName' for the 'syn-nodejs-puppeteer-3.4' runtime/);
});

testDeprecated('recent runtimes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also unit test that fileName.functionName and folder/fileName.functionName passes the regex for recent runtimes

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 31, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review August 2, 2023 12:54

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Comment on lines 169 to 171
if (handler !== 'index.handler') {
throw new Error(`The handler for inline code must be "index.handler" (got "${handler}")`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see anyone complaining about this, and it looks right to me. So lets keep it for now

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lpizzinidev!

@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: fad31f9
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 1eaec92 into aws:main Aug 2, 2023
8 checks passed
@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

synthetics: cdk requires handler to end in .handler when synthetics do not
3 participants