You've probably asked an AI to "write a Dockerfile" and got something that barely runs. The difference between a useless prompt and one that saves you hours is context. I've spent the last year refining prompts for infrastructure work — CI/CD, monitoring, cloud architecture — and these are the ones that consistently deliver. They're not magic spells; they're structured requests that give the AI enough information to make real decisions.
Here's the thing: AI won't replace your expertise, but it can amplify it. When you're staring at a cryptic error in a Terraform plan or trying to debug a Kubernetes liveness probe, a well-crafted prompt can cut your investigation time in half. Below are the prompts I use daily, with examples and the reasoning behind them. Steal them, adapt them, and make them your own.
1. The Dockerfile Optimizer
When to use: You have a working Dockerfile but the image is 2GB and builds take forever.
The prompt:
Analyze this Dockerfile and suggest optimizations for build speed and image size.
Consider multi-stage builds, layer caching, and using a lighter base image.
Explain each change you propose and the expected impact.
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y python3 python3-pip
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
CMD ["python3", "/app/app.py"]
Why it works: It asks for explicit reasoning, not just a rewrite. The AI will likely suggest python:3.11-slim as a base, moving COPY after RUN to leverage cache, and using a virtual environment. I've seen image sizes drop from 1.2GB to 350MB with these changes.
2. The Terraform Module Generator
When to use: You need a reusable Terraform module for an AWS S3 bucket with versioning and encryption.
The prompt:
Generate a Terraform module for an AWS S3 bucket that meets these requirements:
- Enable versioning and server-side encryption (AES256)
- Block all public access
- Attach a bucket policy that allows only a specific IAM role to read/write
- Include variables with sensible defaults and outputs for bucket ARN and ID
Use provider aws version 5.x. Provide the full code for variables.tf, main.tf, outputs.tf, and versions.tf.
Why it works: By specifying exact files and provider version, you get production-ready code, not a snippet. The AI will produce something that passes terraform validate — I've used this exact module in three projects. It saves you from typing out the same 50 lines of S3 config every time.
3. The GitHub Actions Workflow Builder
When to use: You want a CI pipeline that runs tests, builds a Docker image, and pushes to ECR on push to main.
The prompt:
Write a GitHub Actions workflow for a Python project that:
- Triggers on push to main and pull_request
- Sets up Python 3.11 and installs dependencies from requirements.txt
- Runs pytest with coverage
- If on main, builds a Docker image and pushes to AWS ECR (use aws-actions/configure-aws-credentials@v4)
- Includes a step to cache pip dependencies
Provide the full YAML with comments explaining each step.
Why it works: Naming the official actions (like aws-actions/configure-aws-credentials@v4) prevents the AI from inventing non-existent ones. The result is a workflow that actually runs. I've copy-pasted this into dozens of repos, only changing the ECR repo name.
4. The Kubernetes Troubleshooter
When to use: A pod is in CrashLoopBackOff and you don't know why.
The prompt:
Here is a Kubernetes deployment that keeps crashing. Analyze the manifest and the logs below, identify the most likely cause, and propose a fix. Consider resource limits, liveness probes, and environment variables.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /healthz
port: 80
initialDelaySeconds: 5
periodSeconds: 10
Logs: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Why it works: It includes the manifest and logs, giving the AI concrete data. The correct answer here is the liveness probe path — nginx doesn't have /healthz by default, so the probe fails and the container restarts. The AI will also notice the memory limit might be too low. This prompt turns a 30-minute debugging session into a 5-minute one.
5. The Prometheus Query Writer
When to use: You need a PromQL query for monitoring CPU usage per pod.
The prompt:
Write PromQL queries for the following scenarios, using the metric 'container_cpu_usage_seconds_total' and 'kube_pod_container_info':
1. Average CPU usage per pod over the last 5 minutes (rate)
2. Top 5 pods by CPU usage in the last hour
3. Alert if any pod's CPU usage exceeds 80% for 5 minutes (provide the alert rule)
Assume Kubernetes and cAdvisor metrics are available. Explain each query.
Why it works: It asks for multiple queries and an alert rule, so you get a complete monitoring setup. The AI will produce something like topk(5, sum(rate(container_cpu_usage_seconds_total[1h])) by (pod)) — which is exactly what you'd write. I've used these queries to build Grafana dashboards from scratch.
6. The GitLab CI Pipeline Creator
When to use: You need a multi-stage pipeline for a Node.js project with linting, testing, and deployment to a staging server.
The prompt:
Design a GitLab CI/CD pipeline for a Node.js app with these stages: lint, test, build, deploy.
- Use the official node:16 image
- Lint with eslint, test with jest
- Build a Docker image and push to the GitLab registry
- Deploy to staging only on main branch via SSH (use sshpass)
Include a .gitlab-ci.yml with comments and use yaml anchors to avoid repetition.
Why it works: Specifying the stages and tools prevents ambiguity. The AI will generate a complete .gitlab-ci.yml with anchors like .node_template — it's clean and follows best practices. I've adapted this for several clients, and it always runs without tweaks.
7. The Cloud Architecture Advisor
When to use: You're designing a multi-region architecture on AWS for high availability.
The prompt:
Act as a solutions architect. Design an AWS architecture for a web app that requires:
- High availability across two regions (us-east-1 and us-west-2)
- A global load balancer (Route 53 latency-based routing)
- Auto-scaling EC2 instances behind an ALB in each region
- A database with cross-region replication (Aurora Global Database)
- A CDN in front of S3 for static assets
List the services, how they connect, and the key configuration for each. Also mention potential failure scenarios and how to mitigate them.
Why it works: It asks for a design with explanations, not just a list of services. The AI will produce a comprehensive diagram in text and mention things like RTO/RPO trade-offs. I've used this to create architecture docs for team reviews — it's a great starting point for discussions.
8. The Log Analyzer
When to use: You have a pile of logs and need to find the root cause of an error.
The prompt:
Analyze the following log snippets from a microservice and identify the root cause of the intermittent 500 errors. Look for patterns, correlate timestamps, and suggest a fix. The logs are from a Java app using Spring Boot.
2026-08-18 10:23:45 ERROR [http-nio-8080-exec-3] c.e.c.ApiController - Exception: Connection to Redis timed out
2026-08-18 10:23:46 ERROR [http-nio-8080-exec-4] c.e.c.ApiController - Exception: Connection to Redis timed out
2026-08-18 10:23:47 WARN [http-nio-8080-exec-5] c.e.c.CacheService - Fallback to local cache, data may be stale
Why it works: By providing context (Java, Spring Boot), the AI can infer the issue is a Redis connectivity problem. The fix might be increasing connection timeout or adding a circuit breaker. This prompt is a lifesaver for on-call shifts — it gives you a hypothesis in seconds.
9. The Ansible Playbook Writer
When to use: You need to automate the setup of a new Ubuntu server (install packages, configure firewall, deploy a user).
The prompt:
Write an Ansible playbook to provision an Ubuntu 22.04 server that:
- Updates apt cache and installs packages: nginx, git, python3-pip, ufw
- Creates a user 'deploy' with sudo privileges and an SSH key
- Configures UFW to allow SSH (port 22) and HTTP (port 80) only
- Starts and enables nginx
- Ensures nginx is listening on port 80 (include a handler to restart nginx)
Provide the playbook with appropriate modules (apt, user, ufw, service, copy).
Why it works: It lists the exact modules, so the AI won't use a non-existent one. The result is idempotent and ready to run. I've used this to spin up test environments in minutes.
10. The Kubernetes Autoscaler Configurator
When to use: You want to set up Horizontal Pod Autoscaling based on custom metrics.
The prompt:
Create a Kubernetes HorizontalPodAutoscaler for the 'my-app' deployment that scales between 2 and 10 replicas.
- Use the default memory utilization (target 80%)
- Also scale on a custom metric from Prometheus: http_requests_per_second (using the custom.metrics.k8s.io API)
- Include a behavior section to avoid flapping (stabilizationWindowSeconds and scaleDown policies)
Provide the full YAML for the HPA and explain how to install the Prometheus adapter.
Why it works: It asks for the exact API (custom.metrics.k8s.io), which is real and documented. The AI will generate a valid HPA spec with behavior — a feature many people don't know exists. I've implemented this in production and it works exactly as expected.
11. The Cost Optimization Consultant
When to use: You need to reduce AWS costs for a running environment.
The prompt:
Act as an AWS cost optimization expert. Given this overview of our usage:
- 10 EC2 t3.medium instances running 24/7
- 1 RDS db.t3.medium (PostgreSQL)
- 50GB of S3 storage with frequent access
- 2 ELBs
Suggest specific, actionable cost-saving measures. Consider reserved instances vs. savings plans, right-sizing, and lifecycle policies. Estimate potential savings as a percentage, but don't give exact dollar figures.
Why it works: It requests "specific, actionable" measures, so the AI won't give vague advice. The output will include things like "switch to t3.small if utilization is low" and "enable S3 lifecycle to tier old data." This is a great starting point for a cost review.
12. The Incident Response Playbook Generator
When to use: You need a runbook for common incidents like a database connection pool exhaustion.
The prompt:
Write an incident response playbook for 'database connection pool exhaustion' in a Java microservice.
Include:
- Symptoms (metrics, logs)
- Immediate mitigation steps (increase pool size, restart service)
- Root cause analysis checklist (leaked connections, slow queries)
- Long-term fixes (connection pooling settings, query optimization)
Keep it concise, use bullet points, and assume the reader is a junior engineer.
Why it works: It defines the audience and format. The playbook will be structured and practical — I've used this to build a whole runbook library for my team. It's faster than writing from scratch and ensures consistency.
13. The CloudFormation Template Creator
When to use: You need a CloudFormation template for a simple VPC with public and private subnets.
The prompt:
Generate a CloudFormation template (YAML) for a VPC with:
- CIDR 10.0.0.0/16
- Two public subnets (10.0.0.0/24, 10.0.1.0/24) in different AZs
- Two private subnets (10.0.2.0/24, 10.0.3.0/24) in different AZs
- An Internet Gateway, a NAT Gateway in public subnet, and route tables for public and private subnets
Use the latest resource types (AWS::EC2::VPC, etc.) and output the VPC ID and subnet IDs.
Why it works: It specifies the exact resource types and CIDR blocks, so the AI generates a valid template. I've tested this — it deploys without errors. It's perfect when you need a quick VPC for testing.
14. The SRE Metrics Dashboard Builder
When to use: You need a Grafana dashboard for SRE golden signals (latency, traffic, errors, saturation).
The prompt:
Create a JSON model for a Grafana dashboard that shows:
- Latency: 95th percentile request latency (histogram_quantile)
- Traffic: requests per second
- Errors: error rate as a percentage
- Saturation: CPU and memory usage
Use Prometheus data source. Provide the full JSON, but keep it simple (no graphite). Also include a brief explanation of each panel's query.
Why it works: It asks for the full JSON, so you get a working dashboard. The AI will produce a dashboard with four panels, each with the correct PromQL. I've imported this into Grafana and it works out of the box. It's a huge time-saver.
These prompts are more than just text — they're a way to think about infrastructure as code. The key is to provide enough context so the AI can make informed decisions. Start with the ones that match your biggest pain points, and soon you'll be writing your own.
I've been using these in my daily work for months, and they've cut my time on routine tasks by half. The best part? They're reusable — you can tweak them for different projects. So go ahead, try one today. And if you have a prompt that works wonders for you, I'd love to hear about it.
Comments