AWS CDK Error: 'No stack found matching 'MyStack'' — Cause, Fix, and Troubleshooting Guide
Fix the CDK error 'No stack found matching MyStack' caused by wrong stack IDs, missing context, or an app that never instantiates that stack.
- #iac
- #infrastructure-as-code
- #cdk
- #troubleshooting
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
This error means you asked the CDK CLI to act on a stack ID that the synthesized cloud assembly does not contain. cdk deploy MyStack first synthesizes your app, collects the set of stacks it produced, then tries to match MyStack against them. If nothing matches — because of a typo, a renamed stack, missing context that gates stack creation, or an app that conditionally never instantiates it — you get this.
You will see it on cdk deploy, cdk synth, or cdk diff:
❌ No stack found matching 'MyStack'. Use "cdk ls" to display names of all stacks.
The key mental model: the CLI matches on the stack construct ID / stack name in the assembly, not your class name or file name. cdk ls is the source of truth for what IDs actually exist.
Symptoms
cdk deploy MyStackfails withNo stack found matching 'MyStack'.cdk lsprints different names than the one you passed.- Works for a teammate but not you (different context values).
- A stack that used to deploy disappears after a refactor or an environment/stage change.
cdk deploy MyStack
No stack found matching 'MyStack'. Use "cdk ls" to display names of all stacks.
Common Root Causes
1. The stack ID differs from what you typed
CDK uses the construct ID passed to the stack, and stages/nesting prefix it. new MyStack(app, 'AppStack') is addressed as AppStack, not MyStack.
cdk ls
AppStack
AppStack/Database # nested
2. Stage or nested-stack path required
Under a Stage, stacks are addressed by their full path. You must use the qualified ID, and often quote it.
Prod/AppStack # not just AppStack
3. Missing context prevents the stack from being created
The app only instantiates the stack when a context value is present, so without it the assembly has zero (or different) stacks.
const env = app.node.tryGetContext('env');
if (env === 'prod') new AppStack(app, 'AppStack'); // never created without -c env=prod
4. Wrong app entrypoint / cdk.json misconfigured
cdk.json’s app command points at a file that doesn’t build the stack you expect, or you are in the wrong directory.
{ "app": "npx ts-node --prefer-ts-exts bin/app.ts" }
5. Synth throws before the stack is registered
An exception earlier in app construction stops execution before your stack is added, so it never appears in the assembly.
How to Diagnose
List the real stack IDs
cdk ls
This is definitive. Whatever it prints is exactly what cdk deploy will match.
List including nested/staged paths
cdk ls --long
Shows full hierarchical IDs so you can pass the correct qualified name.
Pass the context the app needs
cdk ls -c env=prod
If stacks appear only with certain context, that context is required to target them.
Confirm the entrypoint and working directory
cat cdk.json | grep '"app"'
pwd
Check for synth-time errors
cdk synth --verbose
An exception here explains a stack that never shows up.
Fixes
Fix A: use the exact ID from cdk ls
Copy the name verbatim, quoting paths that contain slashes.
cdk deploy AppStack
cdk deploy "Prod/AppStack"
Fix B: supply required context
cdk deploy -c env=prod AppStack
Or persist it so it is always present:
// cdk.json
{ "context": { "env": "prod" } }
Fix C: deploy everything when unsure
cdk deploy --all
Useful to confirm the app synthesizes at all, then narrow to a specific ID.
Fix D: use wildcards for multi-stack selection
cdk deploy "Prod/*"
Fix E: fix the entrypoint / directory
Run from the project root and confirm cdk.json’s app points at the file that instantiates your stack.
What to Watch Out For
- Stack IDs are the construct ID, not the class name — renaming a class does not change the deploy target; changing the ID string does.
- Changing a stack’s construct ID creates a new stack and orphans the old one; only rename deliberately.
- Quote any stack selector containing
/or*so the shell doesn’t expand it. - If you rely on context to gate stacks, document the required
-cflags in the README or bake defaults intocdk.json. cdk lsrunning clean but empty usually means a synth-time exception or wrong entrypoint, not a matching bug.
Related Guides
- AWS CDK Duplicate Construct ID Error
- AWS CDK Cross-Environment Reference Error
- AWS CDK: Has the environment been bootstrapped?
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.