chore(kms): cross-stack usage detection depends on NPM tree#15580
chore(kms): cross-stack usage detection depends on NPM tree#15580mergify[bot] merged 4 commits intomasterfrom
Conversation
KMS keys try to be smart about not generating impossible dependencies between multiple stacks, which CodePipeline takes advantage of for its support stacks. However, because the logic that tests for this case has an `instanceof Construct` in its code path, if there are ever multiple copies of the `constructs` library in the NPM tree the test will fail, and the resulting error will be very confusing. This situation can arise when people flip back and forth between CDK v1 and v2, because `package-lock.json` will contain half-baked dependency trees; people will be looking at their code but the issue will be in invisible state. Be more liberal in detecting that a construct is, in fact, a construct to get around this.
packages/@aws-cdk/aws-kms/lib/key.ts
Outdated
| * multiple copies of the `constructs` library on disk. This can happen | ||
| * when upgrading and downgrading between v2 and v1, and in the use of CDK | ||
| * Pipelines is going to an error that says "Can't use Pipeline/Pipeline/Role in | ||
| * a cross-environment fahsion", which is very confusing. |
| function isConstruct(x: any): x is Construct { | ||
| const sym = Symbol.for('constructs.Construct.node'); | ||
| return (typeof x === 'object' && x && | ||
| (x instanceof Construct // happy fast case | ||
| || !!(x as Construct).node // constructs v10 | ||
| || !!(x as any)[sym])); // constructs v3 | ||
| } No newline at end of file |
There was a problem hiding this comment.
This is how production software looks like!
There was a problem hiding this comment.
Should we move this to the constructs library? Feels like it might be a better place to put this code, no?
There was a problem hiding this comment.
For sure. Don't forget to add it to both versions :)
|
Thank you for contributing! Your pull request will be updated from master 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 master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
KMS keys try to be smart about not generating impossible dependencies between multiple stacks, which CodePipeline takes advantage of for its support stacks. However, because the logic that tests for this case has an `instanceof Construct` in its code path, if there are ever multiple copies of the `constructs` library in the NPM tree the test will fail, and the resulting error will be very confusing. This situation can arise when people flip back and forth between CDK v1 and v2, because `package-lock.json` will contain half-baked dependency trees; people will be looking at their code but the issue will be in invisible state. Be more liberal in detecting that a construct is, in fact, a construct to get around this. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
KMS keys try to be smart about not generating impossible dependencies between multiple stacks, which CodePipeline takes advantage of for its support stacks. However, because the logic that tests for this case has an `instanceof Construct` in its code path, if there are ever multiple copies of the `constructs` library in the NPM tree the test will fail, and the resulting error will be very confusing. This situation can arise when people flip back and forth between CDK v1 and v2, because `package-lock.json` will contain half-baked dependency trees; people will be looking at their code but the issue will be in invisible state. Be more liberal in detecting that a construct is, in fact, a construct to get around this. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
KMS keys try to be smart about not generating impossible dependencies
between multiple stacks, which CodePipeline takes advantage of for
its support stacks.
However, because the logic that tests for this case has an
instanceof Constructin its code path, if there are ever multiple copies of theconstructslibrary in the NPM tree the test will fail, and theresulting error will be very confusing.
This situation can arise when people flip back and forth between
CDK v1 and v2, because
package-lock.jsonwill contain half-bakeddependency trees; people will be looking at their code but the issue
will be in invisible state.
Be more liberal in detecting that a construct is, in fact, a construct
to get around this.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license