$npx -y skills add github/awesome-copilot --skill aws-cost-optimizeAnalyze AWS resources used in the app (IaC files and/or resources in a target account/region) and optimize costs - creating GitHub issues for identified optimizations.
| 1 | # AWS Cost Optimize |
| 2 | |
| 3 | This workflow analyzes Infrastructure-as-Code (IaC) files and AWS resources to generate cost optimization recommendations. It creates individual GitHub issues for each optimization opportunity plus one EPIC issue to coordinate implementation, enabling efficient tracking and execution of cost savings initiatives. |
| 4 | |
| 5 | ## Prerequisites |
| 6 | - AWS CLI configured and authenticated (`aws sts get-caller-identity` succeeds) |
| 7 | - GitHub MCP server configured and authenticated |
| 8 | - Target GitHub repository identified |
| 9 | - AWS resources deployed (IaC files optional but helpful) |
| 10 | |
| 11 | ## Workflow Steps |
| 12 | |
| 13 | ### Step 1: Get AWS Cost Optimization Best Practices |
| 14 | **Action**: Retrieve cost optimization best practices before analysis |
| 15 | **Tools**: `fetch` to retrieve AWS documentation |
| 16 | **Process**: |
| 17 | 1. **Load Best Practices**: |
| 18 | - Fetch `https://docs.aws.amazon.com/cost-management/latest/userguide/cost-optimization-best-practices.html` |
| 19 | - Fetch the AWS Well-Architected Cost Optimization pillar summary |
| 20 | - Use these practices to inform subsequent analysis and recommendations |
| 21 | |
| 22 | ### Step 2: Discover AWS Infrastructure |
| 23 | **Action**: Dynamically discover and analyze AWS resources and configurations |
| 24 | **Tools**: AWS CLI + Local file system access |
| 25 | **Process**: |
| 26 | 1. **Account & Region Discovery**: |
| 27 | - Execute `aws sts get-caller-identity` to confirm account |
| 28 | - Execute `aws configure get region` to determine default region |
| 29 | |
| 30 | 2. **Resource Discovery** (per region): |
| 31 | - EC2 instances: `aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,InstanceType,State.Name,Tags]'` |
| 32 | - RDS instances: `aws rds describe-db-instances --query 'DBInstances[].[DBInstanceIdentifier,DBInstanceClass,Engine,MultiAZ]'` |
| 33 | - Lambda functions: `aws lambda list-functions --query 'Functions[].[FunctionName,Runtime,MemorySize,Architectures]'` |
| 34 | - ECS clusters/services: `aws ecs list-clusters` then `aws ecs describe-services` |
| 35 | - S3 buckets: `aws s3api list-buckets --query 'Buckets[].Name'` |
| 36 | - ElastiCache clusters: `aws elasticache describe-cache-clusters` |
| 37 | - NAT Gateways: `aws ec2 describe-nat-gateways` |
| 38 | - Load Balancers: `aws elbv2 describe-load-balancers` |
| 39 | |
| 40 | 3. **IaC Detection**: |
| 41 | - Scan for IaC files: `**/*.tf`, `**/*.yaml` (CloudFormation/SAM), `**/*.json` (CloudFormation), `**/cdk.json`, `lib/**/*.ts` (CDK) |
| 42 | - Parse resource definitions to understand intended configurations |
| 43 | - Do NOT use application code files — only IaC files as the source of truth |
| 44 | - If no IaC files found: STOP and report to user |
| 45 | |
| 46 | ### Step 3: Collect Usage Metrics & Validate Current Costs |
| 47 | **Action**: Gather utilization data and verify actual resource costs |
| 48 | **Tools**: AWS CLI (CloudWatch, Cost Explorer) |
| 49 | **Process**: |
| 50 | 1. **CloudWatch Metrics** (last 7 days): |
| 51 | ```bash |
| 52 | # EC2 CPU utilization |
| 53 | aws cloudwatch get-metric-statistics \ |
| 54 | --namespace AWS/EC2 --metric-name CPUUtilization \ |
| 55 | --dimensions Name=InstanceId,Value=<id> \ |
| 56 | --start-time $(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ) \ |
| 57 | --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \ |
| 58 | --period 3600 --statistics Average |
| 59 | |
| 60 | # Lambda duration |
| 61 | aws cloudwatch get-metric-statistics \ |
| 62 | --namespace AWS/Lambda --metric-name Duration \ |
| 63 | --dimensions Name=FunctionName,Value=<name> \ |
| 64 | --start-time $(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ) \ |
| 65 | --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \ |
| 66 | --period 86400 --statistics Average,Maximum |
| 67 | ``` |
| 68 | |
| 69 | 2. **AWS Cost Explorer**: |
| 70 | ```bash |
| 71 | aws ce get-cost-and-usage \ |
| 72 | --time-period Start=$(date -u -d '30 days ago' +%Y-%m-%d),End=$(date -u +%Y-%m-%d) \ |
| 73 | --granularity MONTHLY --metrics BlendedCost \ |
| 74 | --group-by Type=DIMENSION,Key=SERVICE |
| 75 | ``` |
| 76 | |
| 77 | 3. **Calculate Baseline Metrics**: CPU/Memory averages, Lambda invocation rates, data transfer patterns, and a realistic current monthly total. |
| 78 | |
| 79 | ### Step 4: Generate Cost Optimization Recommendations |
| 80 | **Action**: Analyze resources to identify optimization opportunities |
| 81 | **Process**: |
| 82 | 1. **Apply Optimization Patterns**: |
| 83 | |
| 84 | **Compute**: |
| 85 | - EC2: Right-size based on CPU/memory (<20% average → downsize), convert On-Demand to Savings Plans, migrate to Graviton/ARM (up to 40% cheaper) |
| 86 | - Lambda: Reduce memory for idle functions, switch to `arm64` (20% cheaper) |
| 87 | - ECS/EKS: Use Fargate Spot for dev/batch workloads |
| 88 | |
| 89 | **Database**: |
| 90 | - RDS: Right-size instance class, convert single-AZ for dev, use Aurora Serverless v2 for variable load |
| 91 | - DynamoDB: Switch Provisioned → On-Demand for unpredictable traffic |
| 92 | - ElastiCache: Right-size node type based on memory utilization |
| 93 | |
| 94 | **Storage**: |
| 95 | - S3: Lifecycle policies (Standard → Standard-IA after 30d → Glacier after 90d), enable Intelligent-Tiering |
| 96 | - EBS: Delete unattached volumes, convert gp2 → gp3 (same performance, 20% cheaper) |