We all know the pain: a sprawling AWS environment, dozens of accounts, and a monthly bill that keeps climbing. When we looked at our own infrastructure, we saw the same issues you're likely facing—orphaned resources, over-provisioned instances, and manual processes that ate up engineer time. The solution wasn't another dashboard or a new cost-management tool; it was a set of carefully crafted prompts for AI assistants that helped us automate our cloud architecture and slash costs by 40% in just three months. Here's the exact playbook we used.
The Problem: AWS Sprawl and Cost Overruns
Our AWS environment had grown organically over two years. Teams spun up EC2 instances for testing and forgot to terminate them. We had unused Elastic IPs, stale snapshots, and a dozen load balancers that were no longer attached to anything. The worst part? We had no automated way to detect these issues. Our engineers spent hours each week manually auditing resources—time that could have been spent on feature development.
The turning point came when our monthly bill hit $50,000, with 30% of it going to resources that were doing nothing. We knew we had to act, and we knew AI could help.
The Solution: Prompt-Driven Automation
We built a library of prompts that guided AI in auditing, optimizing, and automating our AWS infrastructure. Here are the ones that made the biggest impact.
1. The Cost Anomaly Detector
Purpose: Identify unexpected spikes in AWS spending.
Prompt:
You are a cloud cost optimization expert. Analyze the AWS Cost Explorer data for the last 30 days.
Identify any services or accounts where spending has increased by more than 20% compared to the previous month.
For each anomaly, suggest potential causes (e.g., new resource deployment, traffic surge, misconfigured autoscaling)
and recommend specific actions to investigate. Provide a summary table with service, account, percentage increase,
and suggested action.
Example usage:
We ran this prompt weekly. It caught a spike in NAT Gateway charges caused by a misconfigured VPC peering connection. We fixed it within hours, saving $1,200 that month.
2. The Idle Resource Hunter
Purpose: Find and terminate idle or underutilized resources.
Prompt:
You are an AWS optimization specialist. List all EC2 instances that have had a CPU utilization of less than 5%
for the past 7 days. Also identify RDS instances with low connections, and any Elastic IPs not associated with
a running instance. For each resource, provide the resource ID, name, and the estimated monthly cost.
Recommend whether to stop, terminate, or resize each resource, and explain your reasoning. Use the AWS CLI
commands (e.g., `aws ec2 describe-instances`) to gather data.
Example usage:
This prompt found 15 idle EC2 instances and 8 unattached Elastic IPs. We stopped the instances and released the IPs, saving $3,500 per month.
3. The Rightsizing Advisor
Purpose: Suggest optimal instance types based on actual usage.
Prompt:
You are a cloud architect. Analyze the CloudWatch metrics for our EC2 instances over the last 14 days,
focusing on average CPU, memory, and network utilization. For each instance, recommend a smaller instance type
if the utilization is consistently below 20%, or a larger type if it's above 80%. Provide a comparison table
showing current type, recommended type, and the monthly cost difference. Use the `aws ec2 describe-instances`
and `aws cloudwatch get-metric-statistics` commands.
Example usage:
We rightsized 30% of our instances, saving another $2,000 per month. The prompts even suggested switching to Graviton instances for ARM-based workloads, which cut costs by an additional 10%.
4. The Snapshot Cleanup Crew
Purpose: Delete old EBS snapshots that are no longer needed.
Prompt:
You are a data lifecycle expert. List all EBS snapshots older than 60 days that are not referenced by any AMI.
For each snapshot, show the snapshot ID, volume size, creation date, and estimated cost per month. Provide a
recommendation to delete or retain based on compliance requirements. Use the `aws ec2 describe-snapshots` command.
Example usage:
We found 200 snapshots totaling 4 TB of storage. Deleting them saved $400 per month and reduced our backup costs.
5. The Reserved Capacity Planner
Purpose: Determine if Reserved Instances or Savings Plans are worth purchasing.
Prompt:
You are a financial analyst for AWS. Analyze our EC2 usage over the last 90 days. Determine which instances
have consistent, predictable usage (e.g., running 24/7). Based on this, recommend whether to purchase Reserved
Instances or Savings Plans. Calculate the potential savings compared to on-demand pricing. Use AWS Cost Explorer
API to get usage data.
Example usage:
We bought a 1-year Savings Plan for our production instances, reducing costs by 20% on those resources—a monthly saving of $1,800.
6. The Auto-Stop/Start Scheduler
Purpose: Automatically stop non-production instances during off-hours.
Prompt:
You are a DevOps engineer. Create an AWS Lambda function that stops all EC2 instances tagged with
`Environment=dev` at 7 PM UTC and starts them at 7 AM UTC. Use the `boto3` library. Provide the complete
Python code, IAM role policy, and CloudWatch Events rule to schedule the trigger.
Example usage:
We deployed this scheduler for our development and staging environments. It reduced our compute costs by 15% overall, as these environments were only needed during business hours.
7. The S3 Lifecycle Policy Generator
Purpose: Optimize S3 storage costs by moving data to cheaper tiers.
Prompt:
You are a storage optimization expert. Write an S3 lifecycle policy that transitions objects to Standard-IA
after 30 days, to Glacier Instant Retrieval after 90 days, and deletes them after 365 days. Apply this policy
to buckets with the tag `log-data`. Provide the JSON policy and the AWS CLI command to apply it.
Example usage:
Implementing this policy on our log buckets reduced S3 costs by 30%, saving $600 per month.
8. The Security Group Auditor
Purpose: Find overly permissive security groups.
Prompt:
You are a security auditor. List all security groups that have a rule allowing inbound traffic from 0.0.0.0/0
on ports 22, 3389, or 5432. For each, suggest a more restrictive CIDR range based on known IPs. Provide a
report with the security group ID, rule details, and recommended change.
Example usage:
We found several open SSH ports that were a security risk. Tightening these rules not only improved security but also reduced our risk of malicious traffic, which was costing us in data transfer fees.
9. The CloudWatch Alarm Creator
Purpose: Set up proactive cost monitoring.
Prompt:
You are a monitoring specialist. Create CloudWatch alarms for our AWS account that trigger when:
1) EstimatedCharges exceed $100, 2) CPU utilization of any EC2 instance exceeds 90% for 5 minutes,
3) any S3 bucket is publicly accessible. Provide the AWS CLI commands to create these alarms.
Example usage:
The billing alarm alerted us early in the month when costs were trending upward, allowing us to investigate before the bill arrived.
10. The Multi-Account Cost Aggregator
Purpose: Get a unified view of costs across all AWS accounts.
Prompt:
You are a cloud finance expert. Use AWS Organizations to list all accounts in our organization. For each account,
retrieve the current month's cost from Cost Explorer. Provide a summary table with account name, total cost, and
top services. Highlight any accounts that account for more than 20% of the total spend.
Example usage:
We discovered that one account, used for a forgotten project, was responsible for 25% of our bill. We decommissioned it, saving $5,000 per month.
11. The Infrastructure-as-Code Generator
Purpose: Turn manual configurations into Terraform or CloudFormation templates.
Prompt:
You are an IaC expert. Examine the current AWS resources in our account (e.g., VPC, subnets, EC2 instances,
RDS databases) using the AWS CLI. Generate Terraform configuration files that replicate this setup, ensuring
all resources are properly defined. Use the `terraform-provider-aws` syntax. Provide the .tf files and the
commands to apply them.
Example usage:
We converted our entire production environment into Terraform, enabling us to review and optimize the infrastructure as code. This made it easier to spot and eliminate redundant resources.
12. The Cost-Efficiency Report Generator
Purpose: Create a monthly report for management.
Prompt:
You are a financial analyst. Generate a monthly cost report for our AWS environment. Include: total spend,
cost by service, cost by tag (e.g., project, environment), savings achieved from optimization, and a forecast
for next month. Use data from Cost Explorer and our previous optimization actions. Present the report in Markdown.
Example usage:
This report became our single source of truth for discussions with leadership. It helped justify further investments in automation.
The Results: 40% Cost Reduction in 3 Months
By consistently applying these prompts, we achieved the following over three months:
| Action | Monthly Savings |
|---|---|
| Idle resource cleanup | $3,500 |
| Rightsizing instances | $2,000 |
| Snapshot deletion | $400 |
| Savings Plan purchase | $1,800 |
| Auto-stop for dev environments | $2,000 |
| S3 lifecycle policies | $600 |
| Account decommissioning | $5,000 |
| Total | $15,300 |
With our baseline spend of $50,000, that's a 30% reduction in the first month alone, and we continued to optimize, reaching 40% by month three.
Pro Tips for Prompting
- Be specific: Include instance IDs, tags, or timeframes in your prompts to get more accurate results.
- Iterate: Don't expect perfection on the first try. Refine your prompts based on the AI's output.
- Combine with IaC: Use prompts to generate Terraform code, then apply it with your usual CI/CD pipeline.
- Set up recurring runs: Use tools like AWS Lambda or a cron job to run these prompts periodically and email the results.
Final Thoughts
AI-powered prompts are a game-changer for AWS cost optimization. They don't replace human judgment, but they amplify it by handling the tedious work of data gathering and analysis. Our 40% savings came from a combination of prompt-driven insights and our team's expertise in acting on them.
If you're ready to take control of your AWS bill, start with the prompts above. Adapt them to your environment, track your results, and watch the savings pile up. And if you want to learn more about integrating AI into your cloud operations, check out the resources on ASI Biont—we're building the tools to make this even easier.
Comments