From 101c6df4b0c1a842fed77af0a049040e423d92d5 Mon Sep 17 00:00:00 2001 From: ssumanbiswas Date: Sat, 21 Feb 2026 10:04:58 -0500 Subject: [PATCH] Add AWS cost optimization skills for Kiro CLI - aws-cost-optimizer: Cost analysis and recommendations - aws-cost-cleanup: Automated resource cleanup - Includes AWS CLI commands, Python scripts, and Lambda functions - Kiro CLI integration examples - Addresses cost optimization and FinOps use cases --- .../infrastructure/aws-cost-cleanup/SKILL.md | 307 ++++++++++++++++++ .../aws-cost-optimizer/SKILL.md | 190 +++++++++++ 2 files changed, 497 insertions(+) create mode 100644 skills/infrastructure/aws-cost-cleanup/SKILL.md create mode 100644 skills/infrastructure/aws-cost-optimizer/SKILL.md diff --git a/skills/infrastructure/aws-cost-cleanup/SKILL.md b/skills/infrastructure/aws-cost-cleanup/SKILL.md new file mode 100644 index 00000000..b17db4fe --- /dev/null +++ b/skills/infrastructure/aws-cost-cleanup/SKILL.md @@ -0,0 +1,307 @@ +--- +name: aws-cost-cleanup +description: Automated cleanup of unused AWS resources to reduce costs +risk: medium +source: community +category: infrastructure +tags: [aws, automation, cost-reduction, cleanup, kiro-cli] +--- + +# AWS Cost Cleanup + +Automate the identification and removal of unused AWS resources to eliminate waste. + +## Automated Cleanup Targets + +**Storage** +- Unattached EBS volumes +- Old EBS snapshots (>90 days) +- Incomplete multipart S3 uploads +- Old S3 versions in versioned buckets + +**Compute** +- Stopped EC2 instances (>30 days) +- Unused AMIs and associated snapshots +- Unused Elastic IPs + +**Networking** +- Unused Elastic Load Balancers +- Unused NAT Gateways +- Orphaned ENIs + +## Cleanup Scripts + +### Safe Cleanup (Dry-Run First) + +```bash +#!/bin/bash +# cleanup-unused-ebs.sh + +echo "Finding unattached EBS volumes..." +VOLUMES=$(aws ec2 describe-volumes \ + --filters Name=status,Values=available \ + --query 'Volumes[*].VolumeId' \ + --output text) + +for vol in $VOLUMES; do + echo "Would delete: $vol" + # Uncomment to actually delete: + # aws ec2 delete-volume --volume-id $vol +done +``` + +```bash +#!/bin/bash +# cleanup-old-snapshots.sh + +CUTOFF_DATE=$(date -d '90 days ago' --iso-8601) + +aws ec2 describe-snapshots --owner-ids self \ + --query "Snapshots[?StartTime<='$CUTOFF_DATE'].[SnapshotId,StartTime,VolumeSize]" \ + --output text | while read snap_id start_time size; do + + echo "Snapshot: $snap_id (Created: $start_time, Size: ${size}GB)" + # Uncomment to delete: + # aws ec2 delete-snapshot --snapshot-id $snap_id +done +``` + +```bash +#!/bin/bash +# release-unused-eips.sh + +aws ec2 describe-addresses \ + --query 'Addresses[?AssociationId==null].[AllocationId,PublicIp]' \ + --output text | while read alloc_id public_ip; do + + echo "Would release: $public_ip ($alloc_id)" + # Uncomment to release: + # aws ec2 release-address --allocation-id $alloc_id +done +``` + +### S3 Lifecycle Automation + +```bash +# Apply lifecycle policy to transition old objects to cheaper storage +cat > lifecycle-policy.json <90 days) +aws ec2 describe-snapshots \ + --owner-ids self \ + --query 'Snapshots[?StartTime<=`'$(date -d '90 days ago' --iso-8601)'`].[SnapshotId,StartTime,VolumeSize]' \ + --output table +``` + +### Rightsizing Analysis +```bash +# List EC2 instances with their types +aws ec2 describe-instances \ + --query 'Reservations[*].Instances[*].[InstanceId,InstanceType,State.Name,Tags[?Key==`Name`].Value|[0]]' \ + --output table + +# Get RDS instance utilization +aws cloudwatch get-metric-statistics \ + --namespace AWS/RDS \ + --metric-name CPUUtilization \ + --dimensions Name=DBInstanceIdentifier,Value=mydb \ + --start-time $(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%S) \ + --end-time $(date -u +%Y-%m-%dT%H:%M:%S) \ + --period 86400 \ + --statistics Average,Maximum +``` + +## Optimization Workflow + +1. **Baseline Assessment** + - Pull 3-6 months of cost data + - Identify top 5 spending services + - Calculate growth rate + +2. **Quick Wins** + - Delete unattached EBS volumes + - Release unused Elastic IPs + - Stop/terminate idle EC2 instances + - Delete old snapshots + +3. **Strategic Optimization** + - Analyze Reserved Instance coverage + - Review instance types vs. workload + - Implement S3 lifecycle policies + - Consider Spot instances for non-critical workloads + +4. **Ongoing Monitoring** + - Set up AWS Budgets with alerts + - Enable Cost Anomaly Detection + - Tag resources for cost allocation + - Monthly cost review meetings + +## Cost Optimization Checklist + +- [ ] Enable AWS Cost Explorer +- [ ] Set up cost allocation tags +- [ ] Create AWS Budget with alerts +- [ ] Review and delete unused resources +- [ ] Analyze Reserved Instance opportunities +- [ ] Implement S3 Intelligent-Tiering +- [ ] Review data transfer costs +- [ ] Optimize Lambda memory allocation +- [ ] Use CloudWatch Logs retention policies +- [ ] Consider multi-region cost differences + +## Example Prompts + +**Analysis** +- "Show me AWS costs for the last 3 months broken down by service" +- "What are my top 10 most expensive resources?" +- "Compare this month's spending to last month" + +**Optimization** +- "Find all unattached EBS volumes and calculate savings" +- "Identify EC2 instances with <5% CPU utilization" +- "Suggest Reserved Instance purchases based on usage" +- "Calculate savings from deleting snapshots older than 90 days" + +**Implementation** +- "Create a script to delete unattached volumes" +- "Set up a budget alert for $1000/month" +- "Generate a cost optimization report for leadership" + +## Best Practices + +- Always test in non-production first +- Verify resources are truly unused before deletion +- Document all cost optimization actions +- Calculate ROI for optimization efforts +- Automate recurring optimization tasks +- Use AWS Trusted Advisor recommendations +- Enable AWS Cost Anomaly Detection + +## Integration with Kiro CLI + +This skill works seamlessly with Kiro CLI's AWS integration: + +```bash +# Use Kiro to analyze costs +kiro-cli chat "Use aws-cost-optimizer to analyze my spending" + +# Generate optimization report +kiro-cli chat "Create a cost optimization plan using aws-cost-optimizer" +``` + +## Safety Notes + +- **Risk Level: Low** - Read-only analysis is safe +- **Deletion Actions: Medium Risk** - Always verify before deleting resources +- **Production Changes: High Risk** - Test rightsizing in dev/staging first +- Maintain backups before any deletion +- Use `--dry-run` flag when available + +## Additional Resources + +- [AWS Cost Optimization Best Practices](https://aws.amazon.com/pricing/cost-optimization/) +- [AWS Well-Architected Framework - Cost Optimization](https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html) +- [AWS Cost Explorer API](https://docs.aws.amazon.com/cost-management/latest/APIReference/Welcome.html)