-
Notifications
You must be signed in to change notification settings - Fork 4.3k
test(cli): cdk import works when used on a stack containing a nodejs lambda function #33372
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
Conversation
…ith other synth methods
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33372 +/- ##
=======================================
Coverage 80.91% 80.91%
=======================================
Files 236 236
Lines 14258 14258
Branches 2492 2492
=======================================
Hits 11537 11537
Misses 2436 2436
Partials 285 285
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| * | ||
| */ | ||
| integTest( | ||
| 'CDK import adds the metadata properties expected by sam, validates that bundling is not skipped', |
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.
Consider the issue we're trying to fix - does this test accurately simulate the scenario described in the issue?
It does address the root cause that we identified, but it doesn't give us enough guarantees that the original issue is actually fixed. It might be that something else will block the expected behavior. Think about the manual test you ran to validate the fix works, can you reproduce that manual test here?
- Deploy a stack with
NodeJsFunctionconstruct. - Create a bucket out of band
- Run
cdk import --resource-mappings
Should be feasible...
As for the scenarios you put here, they can serve as additional, quicker tests, that help us diagnose the issue in case of failures, but should not be the only ones. Prefer many small tests over fewer large complicated ones.
Also is the withSamIntegrationFixture really needed here? I understand it might be convenient because it has constructs you want as well, but seems like it also has a bunch of other things that we don't need. See if you can write your own stack in the normal app fixture, tailored to your use case.
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.
Pushed some revisions with a test that reproduces the manual steps. I think validation of the metadata is something we can do later, as a nice to have.
…tion lambdas, removed asset metadata test
| const originalPath = process.env.PATH; | ||
|
|
||
| // Install esbuild locally in the temporary directory | ||
| execSync('npm init -y && npm install esbuild', { cwd: tempDir, stdio: 'inherit' }); |
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.
Hmm, this shouldn't be necessary...we have esbuild a bunch in our devDependencies so it should already be installed.
For example: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/package.json#L175
See if you can without it, maybe its just a matter of locating the installed one and adding it to the path, but I believe that shouldn't be necessary as well.
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.
esbuild is needed as a runtime dependency to use it in integration tests, but we only keep it as a dev dependency in some packages. We do not make it available as a runtime dependency because it is not available via JSII, according to @mrgrain. We don't have it as a dependency in @aws-cdk-testing, in either framework-integ or cli-integ package.jsons. I was able to remove the code above, though, by forcing the integ test to use Docker esbuild to bundle the code instead.
|
|
||
| // GIVEN | ||
| const randomPrefix = randomString(); | ||
| const uniqueOutputsFileName = `${randomPrefix}Outputs.json`; // other tests use the outputs file. Make sure we don't collide. |
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.
Every test already gets its own unique directory in fixture.integTestDir so you don't need this.
(I realize its like this in other tests, but they might also be wrong too or just old. double check.)
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.
Removed this prefix.
| process.env.PATH = originalPath; | ||
|
|
||
| // Clean up the temporary directory | ||
| await fs.rm(tempDir, { recursive: true, force: true }); |
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.
Won't be necessary given the esbuild installation step is removed.
| const originalPath = process.env.PATH; | ||
|
|
||
| // Install esbuild locally in the temporary directory | ||
| execSync('npm init -y && npm install esbuild', { cwd: tempDir, stdio: 'inherit' }); |
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.
We need to install esbuild to bundle the NodeJSFunction code. We install it in a temp directory, which is added to PATH.
At the end of the test, the temp directory is removed, and PATH is set back to its original value.
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.
But esbuild is already installed after you run yarn install - there should be no need to explicitly install it during the test. There must already be a test that defines a NodeJsFunction - does it do the same?
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 did find another NodeJsFunction, it passes the option forceDockerBundling: true, which doesn't require esbuild as a runtime dependency. I've added this option to my test.
| sourceMap: false, | ||
| sourcesContent: false, | ||
| target: 'ES2020', | ||
| forceDockerBundling: true, |
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.
In cli-integ, we don't keep a runtime dependency for esbuild. Uses docker esbuild instead.
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 review is outdated)
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
➡️ PR build request submitted to A maintainer must now check the pipeline and add the |
|
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
Improves testing for #33322.
Reason for this change
The original test (removed below) does not adequately test the CDK import fix from the above-mentioned PR. It calls CDK synth, but does not use the CLI and does not test
cdk import.Description of changes
The old test is removed.
The new test ensures that
cdk importworks when an already-deployed stack contains a NodeJSFunction lambda. In our test, we deploy a stack containing a NodeJSFunction Lambda. We also create, orphan, and import an S3 bucket, which replicates the customer scenario in issue #31999.The test:
esbuildso that we can use it for bundling.BucketNameproperty.The test will fail if the import operation fails for any reason.
The test does not assert any specific values or patterns for asset metadata keys. When investigating the issue, the metadata keys were different when using import-synth (skipped bundling) and deploy/diff/synth (did not skip bundling). The difference in the keys was another symptom of the same issue.
Describe any new or updated permissions being added
No permissions changes.
Description of how you validated changes
This PR tests the feature. I ensured that the test failed on code prior to the change in PR #33322, and passes on code following the change.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license