Generating AWS CDK CloudWatch Dashboards with AI Prompts

Infrastructure as Code (IaC) has revolutionized how we provision AWS resources, and the AWS Cloud Development Kit (CDK) is arguably the most powerful tool for the job. However, if you have ever tried to build a comprehensive CloudWatch Dashboard using CDK, you know how frustrating it can be.
Manually typing out GraphWidget dimensions, aligning coordinates, and constructing complex metric math arrays for error rates is tedious and error-prone. Instead of wasting hours on dashboard aesthetics, you can use these engineered AI prompts to generate the complete TypeScript CDK constructs instantly.
Prompt 1: The API Gateway & Lambda Layout
A standard serverless observability dashboard needs to track API Gateway latency, 4xx/5xx errors, and the corresponding Lambda invocation durations. This prompt instructs the AI to generate a properly aligned, multi-row dashboard. Use this in Claude 3.5 Sonnet or ChatGPT:
"Act as a Senior AWS DevOps Engineer. Write an AWS CDK (TypeScript) construct that creates a CloudWatch Dashboard. The dashboard must include two rows. Row 1: A GraphWidget showing API Gateway p90, p95, and p99 latency, and a GraphWidget showing 4xx vs 5xx error counts. Row 2: A GraphWidget for a specific Lambda function's Invocation count and Duration, plus a SingleValueWidget showing concurrent executions. Ensure all widgets are neatly aligned with appropriate width and height properties."Prompt 2: Generating Complex Metric Math
Sometimes raw metrics aren't enough. If you want to display an "Error Rate Percentage" rather than just a raw error count, you need to use CloudWatch Metric Math. Writing this in CDK requires linking IMetric objects to a MathExpression.
Use this prompt to generate the exact math logic:
"Write an AWS CDK TypeScript snippet that creates a CloudWatch MathExpression for an API Gateway. The expression must calculate the total error rate percentage: (4xx errors + 5xx errors) / total requests * 100. Provide the exact code for the metric definitions (m1, m2, m3) and the final MathExpression object to be used in a GraphWidget."Deploying Your Dashboard
Once the AI generates these constructs, simply drop them into your CDK stack and run cdk deploy. By offloading the tedious layout configuration to AI, you can ensure every microservice you deploy has a standardized, highly readable observability dashboard attached to it without losing hours of development time.
Need More Infrastructure Automation Prompts?
Stop writing boilerplate IaC from scratch. Use our free Prompt Builder to engineer highly specific formulas for AWS CloudFormation, CDK, and Terraform.
Launch Prompt Builder