Skip to content

Commit d86170d

Browse files
committed
fix(deploy): restore stack selection strategy for deploy and diff
Adds StackSelectionStrategy.PATTERN_MUST_MATCH with targetStackName to toolkitWrapper.deploy() and toolkitWrapper.diff() calls. Without this, the CDK toolkit fails with "NoStack: CloudFormationStack object does not hold a stack" when deploying projects with HTTP gateways. Also fixes multi-target consistency: uses targetStackName (derived from project name + target name) as the canonical stackName throughout the function, and scopes checkStackDeployability to the target stack only. Adds a guard that fails early if the target stack isn't found in the synthesized assembly.
1 parent 751110c commit d86170d

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/cli/commands/deploy/actions.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ import {
4343
} from '../../operations/deploy/post-deploy-config-bundles';
4444
import { setupHttpGateways } from '../../operations/deploy/post-deploy-http-gateways';
4545
import { enableOnlineEvalConfigs } from '../../operations/deploy/post-deploy-online-evals';
46+
import { toStackName } from '../import/import-utils';
4647
import type { DeployResult } from './types';
48+
import { StackSelectionStrategy } from '@aws-cdk/toolkit-lib';
4749

4850
export interface ValidatedDeployOptions {
4951
target: string;
@@ -248,7 +250,13 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
248250
logger.finalize(false);
249251
return { success: false, error: 'No stacks found to deploy', logPath: logger.getRelativeLogPath() };
250252
}
251-
const stackName = stackNames[0]!;
253+
const targetStackName = toStackName(context.projectSpec.name, target.name);
254+
if (!stackNames.includes(targetStackName)) {
255+
endStep('error', `Stack "${targetStackName}" not found in synthesized stacks`);
256+
logger.finalize(false);
257+
return { success: false, error: `Stack "${targetStackName}" not found`, logPath: logger.getRelativeLogPath() };
258+
}
259+
const stackName = targetStackName;
252260
endStep('success');
253261

254262
// Check if bootstrap needed
@@ -272,7 +280,7 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
272280

273281
// Check stack deployability
274282
startStep('Check stack status');
275-
const deployabilityCheck = await checkStackDeployability(target.region, stackNames);
283+
const deployabilityCheck = await checkStackDeployability(target.region, [stackName]);
276284
if (!deployabilityCheck.canDeploy) {
277285
endStep('error', deployabilityCheck.message);
278286
logger.finalize(false);
@@ -311,7 +319,9 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
311319
}
312320
});
313321
diffIoHost.setVerbose(true);
314-
await toolkitWrapper.diff();
322+
await toolkitWrapper.diff({
323+
stacks: { strategy: StackSelectionStrategy.PATTERN_MUST_MATCH, patterns: [targetStackName] },
324+
});
315325
if (!hasDiffContent) {
316326
console.log('No stack differences detected.');
317327
}
@@ -349,7 +359,9 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
349359
switchableIoHost.setVerbose(true);
350360
}
351361

352-
await toolkitWrapper.deploy();
362+
await toolkitWrapper.deploy({
363+
stacks: { strategy: StackSelectionStrategy.PATTERN_MUST_MATCH, patterns: [targetStackName] },
364+
});
353365

354366
// Disable verbose output
355367
if (switchableIoHost) {

0 commit comments

Comments
 (0)