Description
agentcore deploy --target <name> --diff shows CDK diff for all stacks in the synthesized app, not just the stack corresponding to the specified --target. When multiple targets are defined in aws-targets.json, the --diff flag ignores the --target filter.
Steps to Reproduce
- Configure two or more targets in
aws-targets.json:
[
{ "name": "preprod-east2", "account": "...", "region": "us-east-2" },
{ "name": "default", "account": "...", "region": "us-west-2" }
]
- Run
agentcore deploy --target default --diff
- Observe the output shows diff for both
Stack AgentCore-<project>-preprod-east2 and Stack AgentCore-<project>-default
Expected Behavior
Only the stack for the specified target (AgentCore-<project>-default) should be diffed. The --target flag should filter the diff to the selected target's stack, consistent with how --target scopes other deploy operations.
Actual Behavior
Both stacks are diffed. The output shows Number of stacks with differences: 2 and includes full diff output for both targets, even though only default was specified.
CLI Version
0.11.0
Operating System
macOS
Additional Context
Root cause is in actions.ts. The diff code path calls toolkitWrapper.diff() without passing a stack selection filter:
// line ~197 in actions.ts
await toolkitWrapper.diff();
The CdkToolkitWrapper.diff() method in wrapper.ts accepts a DiffOptions with optional stacks selection, but it's never provided. Since
cdk.ts synthesizes a stack per target, CDK diffs all of them.
Suggested fix - pass the target-specific stack name:
import { StackSelectionStrategy } from '@aws-cdk/toolkit-lib';
await toolkitWrapper.diff({
stacks: {
strategy: StackSelectionStrategy.PATTERN_MUST_MATCH,
patterns: [stackName],
},
});
Note: the same issue possibly also affects toolkitWrapper.deploy() which is also called without stack selection.
Introduced in PR #485 (feat: add --diff flag to deploy command).
Description
agentcore deploy --target <name> --diffshows CDK diff for all stacks in the synthesized app, not just the stack corresponding to the specified --target. When multiple targets are defined in aws-targets.json, the --diff flag ignores the --target filter.Steps to Reproduce
aws-targets.json:agentcore deploy --target default --diffStack AgentCore-<project>-preprod-east2andStack AgentCore-<project>-defaultExpected Behavior
Only the stack for the specified target (
AgentCore-<project>-default) should be diffed. The--targetflag should filter the diff to the selected target's stack, consistent with how--targetscopes other deploy operations.Actual Behavior
Both stacks are diffed. The output shows
Number of stacks with differences: 2and includes full diff output for both targets, even though onlydefaultwas specified.CLI Version
0.11.0
Operating System
macOS
Additional Context
Root cause is in
actions.ts. The diff code path callstoolkitWrapper.diff()without passing a stack selection filter:The CdkToolkitWrapper.diff() method in wrapper.ts accepts a DiffOptions with optional stacks selection, but it's never provided. Since
cdk.ts synthesizes a stack per target, CDK diffs all of them.
Suggested fix - pass the target-specific stack name:
Note: the same issue possibly also affects toolkitWrapper.deploy() which is also called without stack selection.
Introduced in PR #485 (feat: add --diff flag to deploy command).