-
Notifications
You must be signed in to change notification settings - Fork 4.5k
aws-cdk-lib > codepipeline: Setting cliVersion can cause an invalid version of cdk-assets to attempt to be installed #31253
Description
Describe the bug
The property cliVersion in CodePipeline is used to infer the version of cdk-assets to install in the publishAssetsAction.
Since #31119 was released, this causes the install to fail and the pipeline to break.
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Version
2.153.0
Expected Behavior
The pipeline buildspec will be generated with a command to install a version of cdk-assets that is appropriate for the given version of aws-cdk.
Current Behavior
The pipeline buildspec will be generated with a command to install cdk-assets with an invalid version string. This causes the build to fail with the following error.
[Container] 2024/08/29 14:43:38.596103 Running command npm install -g cdk-assets@2.154.1
npm ERR! code ETARGET
npm ERR! notarget No matching version found for cdk-assets@2.154.1.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
Reproduction Steps
Building this CDK Stack will generate a buildspec with the invalid npm install command. Note that CrossAccountZoneDelegationRecord is what triggers the behavior.
The full repo can be found here.
import { App, Stack, StackProps, Stage, StageProps } from 'aws-cdk-lib';
import { Role } from 'aws-cdk-lib/aws-iam';
import { CrossAccountZoneDelegationRecord, HostedZone } from 'aws-cdk-lib/aws-route53';
import { ShellStep, CodePipeline, CodePipelineSource } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
class MyServiceStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// This Construct adds a node with the type `publish-assets` which triggers the behavior.
new CrossAccountZoneDelegationRecord(this, 'cross-account-zone', {
delegatedZone: HostedZone.fromHostedZoneAttributes(this, 'my-hosted-zone', {
hostedZoneId: 'Z01201272X6Y0ABCDE0FG',
zoneName: 'zone.name',
}),
delegationRole: Role.fromRoleName(this, 'my-role', 'my-role-name'),
parentHostedZoneId: 'parent-hosted-zone',
});
}
}
class MyStage extends Stage {
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
new MyServiceStack(this, 'my-stack');
}
}
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const pipeline = new CodePipeline(this, 'my-pipeline', {
synth: new ShellStep('my-build', {
input: CodePipelineSource.gitHub(
'my-org/my-repo',
'main',
),
commands: [
"echo 'hello world'",
],
}),
cliVersion: '2.154.1',
});
const wave = pipeline.addWave('my-wave');
wave.addStage(new MyStage(this, 'my-stage'));
}
}
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const app = new App();
new MyStack(app, 'cdk-assets-bug-dev', { env: devEnv });
app.synth();Possible Solution
Either don't try to infer the version of cdk-assets at all or allow it to be set explicitly if cliVersion is set.
Additional Information/Context
This commit was the source of this issue (PR #31119).
CDK CLI Version
2.154.1
Framework Version
No response
Node.js Version
v20.15.1
OS
Linux
Language
TypeScript
Language Version
5.5.4
Other information
No response