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(lambda): fix so that the commandHook function is called only once during bundling. #32776

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ayame113
Copy link

@ayame113 ayame113 commented Jan 7, 2025

This is my first contribution to aws-cdk! So please let me know if I'm doing something wrong.

Issue # (if applicable)

Closes #31973.

Reason for this change

When using local bundling, the commandHook function was being called twice.
This PR fixes it so that it is only called once.

Description of changes

When the variable shouldBuildImage is true, a createBundlingCommand for the Docker build will be created as before.
When the variable shouldBuildImage is false, a createBundlingCommand for the local build will be created when bundler.local.tryBundle() is called. (Previously, both a createBundlingCommand for the Docker build and for the local build were created.)

After making this change, some tests failed because they were expecting the createBundlingCommand to be called immediately, so I added forcedDockerBundling: true to some of the tests.

Note: I was going to send a patch to aws-cdk-lib, but I found a similar code in aws-lambda-go-alpha, so I fixed it at the same time. Is that okay?

Description of how you validated changes

I've added a unit test.

Checklist


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

@ayame113 ayame113 changed the title chore(aws-cdk-lib): Fix so that the commandHook` function is called only once during bundling. chore(aws-cdk-lib): Fix so that the commandHook function is called only once during bundling. Jan 7, 2025
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Jan 7, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 7, 2025 11:07
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.

@ayame113 ayame113 changed the title chore(aws-cdk-lib): Fix so that the commandHook function is called only once during bundling. chore(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. Jan 7, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 7, 2025 11:14

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

@ayame113
Copy link
Author

ayame113 commented Jan 7, 2025

@Mergifyio update

Copy link
Contributor

mergify bot commented Jan 7, 2025

update

✅ Branch has been successfully updated

@ayame113 ayame113 changed the title chore(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. fix(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. Jan 7, 2025
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.

@ayame113 ayame113 changed the title fix(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. chore(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. Jan 7, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 7, 2025 11:32

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 7, 2025
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks 👍
A couple of comments:

  1. I'd classify the PR as a fix(lambda) instead of a chore (that will require an integration test update as well to verify the change)
  2. Do we need to fix the behavior for Python runtimes as well?

@ayame113 ayame113 changed the title chore(aws-cdk-lib): fix so that the commandHook function is called only once during bundling. fix(lambda): fix so that the commandHook function is called only once during bundling. Jan 9, 2025
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.

@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 Jan 9, 2025
@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

@ayame113
Copy link
Author

ayame113 commented Jan 9, 2025

@lpizzinidev

Thank you for the review! 👍

  1. I'd classify the PR as a fix(lambda) instead of a chore (that will require an integration test update as well to verify the change)

I fixed the PR title. Thanks.

I have a question about integration testing.
What kind of integration testing is necessary?

a. Deploy the Lambda stack and confirm that the commandHook is called only once.
b. Deploy the Lambda stack and confirm that no errors occur.

In the case of a, I'm wondering how to test it. Can I use jest for integration testing?
In the case of b, can I be exempted from adding a test because it is covered by existing tests?

  1. Do we need to fix the behavior for Python runtimes as well?

I think this logic is unnecessary for the Python runtime because there is no distinction between Docker bundling and Local bundling.

@lpizzinidev
Copy link
Contributor

@ayame113 Thanks for the follow up 👍

What kind of integration testing is necessary?

Looking at the docs, following

  1. Changing functionality that affects asset bundling

I guess an update/re-run to this Node test and this GO test should be enough.

@ayame113
Copy link
Author

ayame113 commented Jan 13, 2025

@lpizzinidev

I guess an update/re-run to this Node test and this GO test should be enough.

Thanks for the clarification! 👍
I reran those two tests and confirmed there were no snapshot changes that needed to be committed.
(This is expected, since the bundling results do not change whether the commandHooks are called twice or once.)

Please let me know if there are any other changes that should be added.

Verifying integration test snapshots...

   Waiting for 1 more (integ.function)
  UNCHANGED  integ.function 419.943s

Snapshot Results: 

Tests:    1 passed, 1 total

@lpizzinidev
Copy link
Contributor

@ayame113
Thanks for running the tests 👍
I think it would still be useful to update an integration test to make the build ✅ and have this PR merged earlier.

a. Deploy the Lambda stack and confirm that the commandHook is called only once.

Can we use an invokeFunction assertion to verify that the Lambda is bundling once? (sample code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-lambda-nodejs): commandHooks is called twice when local bundling
3 participants