惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
NISL@THU
NISL@THU
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
V
V2EX
G
GRAHAM CLULEY
TaoSecurity Blog
TaoSecurity Blog
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Latest news
Latest news
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
S
Schneier on Security
I
Intezer
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
爱范儿
爱范儿
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
美团技术团队
B
Blog RSS Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
AI Can't Fix What It Can't See: How cdk diagnose Enables Autonomous CDK Remediation
Pahud Hsieh · 2026-05-05 · via DEV Community

AI Can't Fix What It Can't See: How cdk diagnose Enables Autonomous CDK Remediation

Current Behavior vs. What We Want

Today, when a CDK deployment fails through a pipeline, the remediation loop looks like this:

Developer ──▶ Push code ──▶ Pipeline ──▶ CFN deploy ──▶ ❌ Fails
                                                          │
    ┌─────────────────────────────────────────────────────┘
    │
    ▼
Developer manually:
    1. Opens pipeline UI
    2. Finds the failed stage
    3. Navigates to CloudFormation console
    4. Locates the failed change set
    5. Reads the CFN error message
    6. Mentally translates CFN → CDK
    7. Edits code, pushes, waits for pipeline again

🤖 Developer: "AI, fix this deployment for me"
🤖 AI: "Sure! I'll fix the CloudFormation template for you."
🤖 Developer: "...that's not how CDK works."

The AI has no access to the error, no construct path, no source location.
The best it can do is guess — and it guesses wrong, offering to edit
CloudFormation YAML instead of your CDK source code. Totally useless.

Enter fullscreen mode Exit fullscreen mode

So what do we actually need for AI to address the root cause from CDK's perspective?

We need a diagnosis report that's actionable for AI to fix CDK code — not CloudFormation templates. Specifically, the AI needs:

  1. What failed — which CloudFormation resource was rejected and why
  2. Where in CDK — the construct path (MyStack/MyFunction/LogGroup) that maps the CFN logical ID back to your construct tree
  3. Where in source code — the exact file and line number (lib/my-stack.ts:8:5) where the construct was created
  4. What to do — enough context to reason about the fix (set a feature flag? import the existing resource? change the removal policy?)

That's exactly what cdk diagnose provides.

With cdk diagnose, the expected behavior becomes:

Developer ──▶ Push code ──▶ Pipeline ──▶ CFN deploy ──▶ ❌ Fails
                                                          │
    ┌─────────────────────────────────────────────────────┘
    │
    ▼
Developer (or AI agent):
    1. Runs: cdk diagnose MyStack
    2. Gets: construct path + error + source location
    3. Fixes the code
    4. Redeploys ✅

🤖 AI agent can do steps 1–4 autonomously.
   The entire loop is CLI-driven, machine-readable,
   and can be designed as an autonomous agent that
   diagnoses, fixes, and redeploys — without human intervention.

Enter fullscreen mode Exit fullscreen mode

The difference: cdk diagnose turns a manual, console-bound, human-only workflow into a single command that both humans and AI agents can use. This is what makes AI-assisted remediation possible.

The Problem in Detail

Here's a scenario every CDK developer has lived through.

You write a perfectly valid CDK application. You run cdk synth — clean output, valid CloudFormation template, no errors. You push your code, the pipeline picks it up, and then... somewhere in the deployment, CloudFormation rejects it.

Now what?

If you deployed with cdk deploy, you're fine — the CLI catches the error, enriches it with your CDK construct path, and even points you to the source location in your code. But most teams don't deploy that way. They push to a pipeline — CDK Pipelines, CodePipeline, or an internal CI/CD system — and CDK only runs synth. The actual deployment happens through CloudFormation APIs directly.

When that deployment fails, the error is buried. You open the pipeline UI. Click through to the failed stage. Find the CloudFormation stack. Federate to the console. Navigate to the change set. And finally, you see something like:

Resource of type 'AWS::S3::Bucket' with identifier
'my-app-bucket' already exists.

Enter fullscreen mode Exit fullscreen mode

Three to five clicks deep, in CloudFormation's language, with no connection back to your CDK code.

This is the gap that cdk diagnose fills.

┌──────────────┐     ┌──────────────┐     ┌──────────────────────┐
│  Developer   │────▶│  cdk synth   │────▶│  Pipeline / CI/CD    │
│  writes CDK  │     │  ✅ Looks     │     │  deploys to CFN      │
│              │     │     great!    │     │                      │
└──────────────┘     └──────────────┘     └──────────┬───────────┘
                                                     │
                                                     ▼
                                          ┌──────────────────────┐
                                          │   CloudFormation     │
                                          │   ❌ Deploy fails     │
                                          └──────────┬───────────┘
                                                     │
                          ┌──────────────────────────┴──────────────────────────┐
                          │                                                     │
                          ▼                                                     ▼
               ┌─────────────────────┐                            ┌──────────────────────┐
               │  WITHOUT diagnose   │                            │  WITH cdk diagnose   │
               │                     │                            │                      │
               │  1. Open Pipeline   │                            │  $ cdk diagnose      │
               │  2. Find stage      │                            │                      │
               │  3. Find stack      │                            │  ❌ MyFunction        │
               │  4. Open console    │                            │    🛑 LogGroup        │
               │  5. Find changeset  │                            │       already exists  │
               │  6. Read CFN error  │                            │    📍 stack.ts:8:5   │
               │  7. Translate to    │                            │  One command.         │
               │     CDK manually    │                            │  Source location.     │
               │                     │                            │  AI can act on this.  │
               │  🤖 AI can't help   │                            │  🤖 AI fixes code ✅  │
               └─────────────────────┘                            └──────────────────────┘

Enter fullscreen mode Exit fullscreen mode

What is cdk diagnose?

cdk diagnose is a new CDK CLI subcommand that inspects a CloudFormation stack's last failed deployment and surfaces the root cause with CDK-aware context — construct paths, source locations, and actionable fix suggestions.

cdk --unstable=diagnose diagnose MyStack

Enter fullscreen mode Exit fullscreen mode

It queries CloudFormation directly via DescribeChangeSet and related APIs, then enriches the raw error using CDK metadata (aws:cdk:path) to map CloudFormation logical IDs back to your constructs and source code.

The key insight: it works regardless of how the stack was deployed. Pipeline, cdk deploy, manual CloudFormation API call — doesn't matter. If the stack exists and it failed, cdk diagnose can tell you why.

A Real Example: The CDK Upgrade That Breaks Everything

Let me walk through a scenario that hit hundreds of real CDK users as a P0 issue (aws-cdk#34612). It's the kind of failure that makes cdk diagnose invaluable — because the developer did nothing wrong.

The Setup

You have a Lambda function that's been running in production for months:

import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';

export class MyAppStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new lambda.Function(this, 'MyFunction', {
      runtime: lambda.Runtime.NODEJS_20_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('lambda'),
      logRetention: cdk.aws_logs.RetentionDays.ONE_WEEK,
    });
  }
}

Enter fullscreen mode Exit fullscreen mode

Standard code. Deployed and working. No issues.

Then you upgrade aws-cdk-lib from 2.199.0 to 2.200.0 — a routine version bump. You change nothing else in your code.

Synth: Looks Perfect

$ cdk synth

Enter fullscreen mode Exit fullscreen mode

No errors. The template looks fine. You push to your pipeline.

Deploy: Fails

CREATE_FAILED | AWS::Logs::LogGroup | MyFunctionLogGroup
Resource of type 'AWS::Logs::LogGroup' with identifier
'/aws/lambda/MyFunction' already exists.

Enter fullscreen mode Exit fullscreen mode

Wait — what? You didn't add a log group. You didn't change anything. Why is CloudFormation suddenly trying to create one?

What Happened

CDK 2.200.0 introduced a new feature flag @aws-cdk/aws-lambda:useCdkManagedLogGroup that defaults to true. This causes CDK to add an explicit AWS::Logs::LogGroup resource to your template for every Lambda function. The intent is good — CDK wants to manage the log group lifecycle so it can set retention policies and clean up on deletion.

But here's the catch: when your Lambda function first ran, AWS Lambda automatically created a log group named /aws/lambda/MyFunction. That log group already exists. Now CDK's template tries to create the same log group, and CloudFormation rejects it.

The developer did nothing wrong. The synth output looks correct. The failure only happens at deploy time because it depends on the runtime state of the AWS account.

Diagnose: Root Cause + Source Location

$ cdk --unstable=diagnose diagnose MyAppStack

🔍 Synthesizing with debug information. This may take a bit longer.
❌ Stack MyAppStack:
 └─ MyAppStack
     └─ MyFunction
         └─ LogGroup  (AWS::Logs::LogGroup MyFunctionLogGroupXXXXXXXX)
            🛑 Resource of type 'AWS::Logs::LogGroup' with identifier
               '/aws/lambda/MyFunction' already exists.
            Source Location: new MyAppStack (lib/my-app-stack.ts:8:5)

Enter fullscreen mode Exit fullscreen mode

Now an AI agent has everything it needs:

  • What failed: AWS::Logs::LogGroup for /aws/lambda/MyFunction already exists
  • Where in CDK: MyAppStack/MyFunction/LogGroup — it's the log group associated with the Lambda construct
  • Where in source: lib/my-app-stack.ts:8:5 — the new lambda.Function(...) call
  • Context to reason about the fix: this is a known issue with the useCdkManagedLogGroup feature flag in CDK 2.200+

The AI-Assisted Fix

An AI agent reading this diagnosis can reason through the fix:

  1. The log group already exists because Lambda auto-created it
  2. CDK 2.200+ now tries to explicitly manage it
  3. Fix option A: Set the feature flag to false to restore previous behavior:
   // cdk.json
   { "context": { "@aws-cdk/aws-lambda:useCdkManagedLogGroup": false } }

Enter fullscreen mode Exit fullscreen mode

  1. Fix option B: Import the existing log group so CDK can manage it going forward

This isn't a trivial "remove the hardcoded name" fix. It requires understanding CDK feature flags, Lambda log group lifecycle, and the tradeoffs between the two fix options. That's exactly the kind of reasoning AI agents excel at — when they have the right input.

Another Example: The Named Resource Trap

The Lambda log group issue is subtle — it only surfaces during a CDK upgrade. But there's an even more common class of failures that hits teams every day: named resources that already exist (aws-cdk#16686, aws-cdk#6183).

new s3.Bucket(this, 'DataBucket', {
  bucketName: 'my-team-data-bucket',
});

Enter fullscreen mode Exit fullscreen mode

Perfectly valid CDK. Synth passes.

cdk synth output

But if that bucket already exists in the account — from a previous stack that was torn down, from another team, or from a manual aws s3 mb — CloudFormation rejects it:

Resource of type 'AWS::S3::Bucket' with identifier
'my-team-data-bucket' already exists.

Enter fullscreen mode Exit fullscreen mode

Same pattern with IAM roles, SQS queues, or any resource with a hardcoded physical name. CDK can't catch this at synth time because it's a runtime check against the actual state of your AWS account.

And here's what you see in the CloudFormation console — not helpful at all:

CloudFormation console error

With cdk diagnose:

$ cdk --unstable=diagnose diagnose MyAppStack

❌ Stack MyAppStack:
 └─ MyAppStack
     └─ DataBucket
         └─ Resource  (AWS::S3::Bucket DataBucketXXXXXXXX)
            🛑 Resource of type 'AWS::S3::Bucket' with identifier
               'my-team-data-bucket' already exists.
            Source Location: new MyAppStack (lib/my-app-stack.ts:6:5)

Enter fullscreen mode Exit fullscreen mode

An AI agent sees this and can reason: "The bucket name conflicts with an existing resource. I should either remove the hardcoded bucketName to let CloudFormation generate a unique name, or import the existing bucket with cdk import."

cdk diagnose output

Simple to understand, but impossible for AI to act on without cdk diagnose surfacing the error in the first place.

Why This Matters for AI

Here's where it gets interesting.

Without cdk diagnose, an AI agent has no way to help you fix a deployment failure. The error is locked behind a multi-step console navigation that requires browser interaction, AWS console federation, and human eyeballs. There's no CLI command, no API, no machine-readable output for the agent to consume.

With cdk diagnose, the entire remediation loop becomes automatable:

Pipeline fails
    │
    ▼
AI runs: cdk diagnose MyStack
    │
    ▼
AI reads structured output:
  "LogGroup '/aws/lambda/MyFunction' already exists
   at MyAppStack/MyFunction/LogGroup
   source: lib/my-app-stack.ts:8:5"
    │
    ▼
AI reasons: "CDK 2.200+ feature flag issue.
  Fix: set @aws-cdk/aws-lambda:useCdkManagedLogGroup to false"
    │
    ▼
AI edits cdk.json, redeploys
    │
    ▼
✅ Deployment succeeds

Enter fullscreen mode Exit fullscreen mode

This is AI-assisted remediation. The AI agent can:

  1. Diagnose — run cdk diagnose to get the structured error with construct path and source location
  2. Reason — understand this is a CDK version upgrade issue involving feature flags and Lambda log group lifecycle
  3. Fix — edit cdk.json to set the feature flag, or import the existing log group
  4. Verify — redeploy and confirm the fix works

This isn't a simple text substitution. The AI needs to understand CDK concepts, feature flags, and AWS service behavior to pick the right fix. But it can only do that reasoning if it has the structured diagnosis as input. cdk diagnose is that input.

Putting It Together: Kiro CLI as the Autonomous Remediation Agent

So we have cdk diagnose producing structured, machine-readable error output. But who runs it? Who reads the output, reasons about the fix, edits the code, and redeploys?

This is where Kiro CLI comes in. Kiro CLI's chat subcommand supports a headless mode (--no-interactive) — no IDE, no GUI, just a terminal agent that can read files, run commands, edit code, and iterate. It's designed for exactly this kind of autonomous workflow.

# After a failed pipeline deployment, just run:
kiro-cli chat --no-interactive --trust-all-tools \
  "My CDK deployment of MyAppStack failed. \
   Run cdk diagnose to find the root cause and fix it."

Enter fullscreen mode Exit fullscreen mode

The --no-interactive flag runs Kiro in headless mode — it executes the task and exits, no human input needed. The --trust-all-tools flag lets the agent run shell commands (like cdk diagnose and cdk deploy) without pausing for approval prompts.

Here's what happens under the hood:

┌─────────────────────────────────────────────────────────┐
│  kiro chat (headless agent)                             │
│                                                         │
│  1. Runs: cdk --unstable=diagnose diagnose MyAppStack   │
│                                                         │
│  2. Reads output:                                       │
│     "LogGroup '/aws/lambda/MyFunction' already exists"  │
│     "Source: lib/my-app-stack.ts:8:5"                   │
│                                                         │
│  3. Reads lib/my-app-stack.ts to understand context     │
│                                                         │
│  4. Reasons: "CDK 2.200+ feature flag issue.            │
│     The log group was auto-created by Lambda.            │
│     Fix: set useCdkManagedLogGroup to false"            │
│                                                         │
│  5. Edits cdk.json:                                     │
│     + "@aws-cdk/aws-lambda:useCdkManagedLogGroup": false│
│                                                         │
│  6. Runs: cdk deploy                                    │
│                                                         │
│  7. ✅ Deployment succeeds                               │
└─────────────────────────────────────────────────────────┘

Enter fullscreen mode Exit fullscreen mode

The key: Kiro CLI operates entirely in the terminal. No browser, no console, no clicking. It can run in a CI/CD pipeline's post-failure hook, in an SSH session, or on a developer's laptop. Combined with cdk diagnose, it closes the full loop from failure detection to automated fix.

This is what the autonomous remediation workflow looks like end to end:

Pipeline deploys ──▶ CFN fails
                        │
                        ▼
              Post-failure hook triggers:
              kiro-cli chat --no-interactive --trust-all-tools \
                "diagnose and fix MyAppStack"
                        │
                        ▼
              Kiro CLI (headless):
                cdk diagnose → read error → edit code → cdk deploy
                        │
                        ▼
                   ✅ Fixed and redeployed
                   (or: opens PR with the fix for human review)

Enter fullscreen mode Exit fullscreen mode

No human in the loop for the diagnosis and fix. A human reviews the PR if you want that gate — but the heavy lifting is done.

Here's what it looks like in practice — Kiro CLI diagnosing, fixing, and redeploying a failed stack in under 2 minutes:

$ kiro-cli chat --no-interactive --trust-all-tools \
    "My CDK stack CdkDiagnoseStack failed to deploy. \
     Run cdk diagnose to find the root cause and fix it."

> Let me start by running cdk diagnose to understand what went wrong.

🔍 Synthesizing with debug information. This may take a bit longer.
❌ Stack CdkDiagnoseStack:
Early validation failed for change set cdk-deploy-change-set:
 └─ CdkDiagnoseStack
     └─ MyBucket
         └─ Resource  (AWS::S3::Bucket MyBucketF68F3FF0)
            🛑 Resource of type 'AWS::S3::Bucket' with identifier
               'cdk-diagnose-demo-903779448426-us-east-1' already exists.
            Source Location:
              new CdkDiagnoseStack (lib/cdk-diagnose-stack.ts:12:5)

> The issue is clear: the S3 bucket has a hardcoded name that already
  exists. The fix is to remove the hardcoded name and let CloudFormation
  generate a unique one.

Updating: lib/cdk-diagnose-stack.ts
  12, 12:     new s3.Bucket(this, 'MyBucket', {
- 13    :       bucketName: 'cdk-diagnose-demo-903779448426-us-east-1',
  14, 13:       removalPolicy: cdk.RemovalPolicy.DESTROY,

> Now let me destroy the failed stack and redeploy:

 ✅  CdkDiagnoseStack: destroyed

CdkDiagnoseStack: deploying... [1/1]
CdkDiagnoseStack | 7/7 | CREATE_COMPLETE | AWS::CloudFormation::Stack

 ✅  CdkDiagnoseStack

✨  Deployment time: 36.28s

> ✅ Done. Here's what happened:
  1. cdk diagnose identified the root cause: hardcoded bucket name
     already existed, causing "resource already exists" error.
  2. Fix: Removed the hardcoded bucketName property.
  3. Redeployed successfully.

 ▸ Credits: 1.74 • Time: 1m 38s

Enter fullscreen mode Exit fullscreen mode

Try It

cdk diagnose is available now in the latest CDK CLI (v2.1120.0+) behind the unstable flag:

npx cdk --unstable=diagnose diagnose <stack-name>

Enter fullscreen mode Exit fullscreen mode

The --unstable flag indicates the API may still change, but the feature is production-ready and fully supported.

To try the full autonomous remediation flow with Kiro CLI:

# 1. Install Kiro CLI: https://kiro.dev/downloads/
# 2. After a failed deployment:
kiro-cli chat --no-interactive --trust-all-tools \
  "My CDK stack MyAppStack failed to deploy. \
   Run cdk diagnose, find the root cause, and fix the code."

Enter fullscreen mode Exit fullscreen mode

If you want a hands-on demo, here's a minimal CDK app that will fail on deploy:

// lib/my-app-stack.ts
import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';

export class MyAppStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new s3.Bucket(this, 'MyBucket', {
      bucketName: 'cdk-diagnose-demo-bucket',
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      autoDeleteObjects: true,
    });
  }
}

Enter fullscreen mode Exit fullscreen mode

Then run:

# 1. Pre-create the bucket so it conflicts
aws s3api create-bucket --bucket cdk-diagnose-demo-bucket

# 2. Deploy — this will fail
npx cdk deploy --require-approval never

# 3. Diagnose
npx cdk --unstable=diagnose diagnose MyAppStack

# 4. Let Kiro fix it
kiro-cli chat --no-interactive --trust-all-tools \
  "My CDK stack MyAppStack failed to deploy. \
   Run cdk diagnose, find the root cause, and fix the code."

# 5. Cleanup
aws s3 rb s3://cdk-diagnose-demo-bucket --force
aws cloudformation delete-stack --stack-name MyAppStack

Enter fullscreen mode Exit fullscreen mode

The gap between "deployment failed" and "here's what to fix" just got a lot smaller. With cdk diagnose and Kiro CLI, it can be fully automated.


cdk diagnose was implemented by Rico Huijbers with contributions from Momo Kornher on the AWS CDK team. The feature landed in aws-cdk-cli#1378.