-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What is the problem?
When requiring aws-cdk and aws-cdk-lib in a project, then the cx-api package gets installed twice:
- once as a dependency of
aws-cdk - once inside
aws-cdk-lib
That causes a problem similar to #14468 because of this bit:
aws-cdk/packages/aws-cdk/lib/api/cloudformation-deployments.ts
Lines 328 to 330 in 4e7a275
| function isAssetManifestArtifact(art: cxapi.CloudArtifact): art is cxapi.AssetManifestArtifact { | |
| return art instanceof cxapi.AssetManifestArtifact; | |
| } |
The instanceof fails because of the class duplication (again, similar thing happened in #14468, see this comment: #14468 (comment)).
I signaled this with CDK v1 here: #14468 (comment) but the same problem happens with CDK v2.
Note: I am requiring both of those package to deploy with the CDK programmatically, not deploying via the CLI. BTW let me know if that is completely not meant to be done that way.
Reproduction Steps
Package.json:
{
"dependencies": {
"aws-cdk": "^2.1.0",
"aws-cdk-lib": "^2.1.0",
"aws-sdk": "^2.1046.0"
}
}
JS file:
const app = new App();
const stack = new Stack(app, 'test-stack', {
env: {
region: 'us-east-1',
name: "dev",
}
});
new Queue(stack, 'Queue');
const stackArtifact = app.synth().getStackByName('test-stack');
const sdkProvider = new SdkProvider(new CredentialProviderChain(), 'us-east-1');
const cloudFormation = new CloudFormationDeployments({ sdkProvider });
await cloudFormation.deployStack({
stack: stackArtifact,
});What did you expect to happen?
isAssetManifestArtifact() should return true. And the deployment should succeed.
What actually happened?
isAssetManifestArtifact() returns false, caused some assets not to be uploaded to S3 (namely the CloudFormation template).
That causes the deployment to fail because the CloudFormation deployment is looking for a template on S3 that doesn't exist (it was never uploaded there).
CDK CLI Version
Not using the CDK CLI
Framework Version
No response
Node.js Version
17.0.1
OS
macOS
Language
Typescript
Language Version
4.1.2
Other information
I have no idea how we could make that instanceof more robust.
BUT even if we did, what if there are other instanceof tests in the codebase? (#14468 tells us that this isn't an isolated problem)
Maybe we should fix the root problem: how can we make sure cx-api (or any other dependency) is installed once in projects that require aws-cdk and aws-cdk-lib?