← Back
Containers Cost Optimization Guide
Service Overview
What are AWS Container Services?
- **Amazon ECS (Elastic Container Service):** Fully managed container orchestration service with no control plane costs
- **Amazon EKS (Elastic Kubernetes Service):** Managed Kubernetes service with control plane costs ($0.10/cluster/hour)
- **AWS Fargate:** Serverless compute engine for containers, pay only for resources consumed
- **AWS App Runner:** Fully managed service for containerized web applications with automatic scaling
Why Cost Optimization Matters
- Container services can represent 20-40% of compute costs in modern applications
- Multiple pricing dimensions (control plane, compute, networking, storage) create complexity
- Auto-scaling capabilities can lead to cost surprises without proper configuration
- Spot instance integration offers up to 90% savings but requires proper termination handling
---
Cost Analysis & Monitoring
Key Cost Metrics to Track
Primary Cost Drivers:
- **EKS Control Plane** - $0.10/cluster/hour ($72/month per cluster)
- **Compute Costs** - EC2 instances, Fargate vCPU/memory, or App Runner compute
- **Data Transfer** - Cross-AZ, cross-region, and internet egress charges
- **Storage** - EBS volumes for persistent storage, ECR image storage
- **Load Balancing** - ALB/NLB costs for service exposure
Cost Allocation Tags:
- Environment (prod, dev, test) for lifecycle management
- Application/Service for cost attribution
- Team/Owner for accountability
- kubernetes.io/cluster/[cluster-name] (automatically applied by EKS)
Using the Power's Tools
Get Container service costs:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"SERVICE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\", \"Amazon Elastic Container Service for Kubernetes\", \"AWS Fargate\"]}}"
})
Analyze EKS Fargate usage patterns:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "DAILY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UsageQuantity\", \"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service for Kubernetes\"]}}"
})
Get container pricing information:
usePower("aws-cost-optimization", "awslabs.aws-pricing-mcp-server", "get_pricing", {
"service_code": "AmazonEKS",
"region": ["us-east-1", "us-west-2"],
"filters": [
{"Field": "productFamily", "Value": "Compute", "Type": "EQUALS"}
]
})
Monitor container resource utilization:
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "ContainerInsights",
"metric_name": "cluster_cpu_utilization",
"dimensions": [{"Name": "ClusterName", "Value": "my-eks-cluster"}],
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 3600,
"statistics": ["Average", "Maximum"]
})
Create container efficiency metrics:
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_data", {
"metric_data_queries": [
{
"id": "cpu_utilization",
"metric_stat": {
"metric": {
"namespace": "ContainerInsights",
"metric_name": "cluster_cpu_utilization",
"dimensions": [{"Name": "ClusterName", "Value": "my-eks-cluster"}]
},
"period": 3600,
"stat": "Average"
}
},
{
"id": "cost_efficiency",
"expression": "cpu_utilization / 100"
}
],
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z"
})
---
Optimization Strategies
1. Right-Sizing & Resource Optimization
Strategy Overview:
- Optimize CPU and memory requests/limits based on actual usage
- Use tools like Kubecost and kube-resource-report for EKS optimization
- Implement proper resource quotas and limits
Implementation Steps:
1. Analyze current resource utilization:
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "compute_optimizer", {
"operation": "get_ecs_service_recommendations"
})
2. EKS Resource Optimization Tools:
- **Kubecost:** Real-time cost allocation by service, deployment, namespace, pod
- **kube-resource-report:** HTML reports showing CPU/memory requests vs usage
- **kube-downscaler:** Scale deployments to zero during off-hours
3. Container Image Optimization:
- Use multi-stage builds to reduce image size
- Leverage Amazon ECR for efficient image storage and transfer
- Implement image scanning for security and efficiency
4. Resource Request Right-Sizing:
- Set appropriate CPU/memory requests based on actual usage
- Use Vertical Pod Autoscaler (VPA) for automatic right-sizing
- Monitor slack cost (difference between requested and used resources)
2. Compute Cost Optimization
EC2 vs Fargate Decision Matrix:
- **Use EC2 when:** Predictable workloads, need for customization, cost-sensitive at scale
- **Use Fargate when:** Variable workloads, minimal operational overhead, rapid scaling needs
Spot Instance Integration:
- **Up to 90% cost savings** on compute costs
- **EKS Spot Support:** Easy configuration with mixed on-demand + spot clusters
- **Node Termination Handler:** Automatically handles spot interruptions
- **Karpenter Integration:** Advanced node provisioning with spot instance support
Analysis Commands:
// Check Spot instance utilization
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"PURCHASE_OPTION\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service for Kubernetes\"]}}"
})
3. Auto-Scaling Optimization
Two-Layer Scaling Strategy:
- **Application Scaling:** Scale number of ECS tasks or EKS pods (HPA)
- **Infrastructure Scaling:** Scale EC2 instances to accommodate new tasks/pods
ECS Scaling Options:
- **Target Tracking:** Scale based on metrics like CPU utilization
- **Step Scaling:** Scale in steps based on CloudWatch alarms
- **Scheduled Scaling:** Predictable scaling for known patterns
- **Predictive Scaling:** ML-based scaling for anticipated load
EKS Scaling Options:
- **Cluster Autoscaler:** Traditional Kubernetes node scaling
- **Karpenter:** Advanced node provisioning with better cost optimization
- **Horizontal Pod Autoscaler (HPA):** Scale pods based on metrics
- **Vertical Pod Autoscaler (VPA):** Adjust resource requests automatically
Implementation:
// Monitor scaling effectiveness
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "ContainerInsights",
"metric_name": "cluster_node_count",
"dimensions": [{"Name": "ClusterName", "Value": "my-eks-cluster"}],
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 3600,
"statistics": ["Average", "Maximum", "Minimum"]
})
4. EKS Auto Mode Cost Benefits
EKS Auto Mode Features:
- **Automatic infrastructure provisioning** with cost optimization
- **Continuous cost optimization** through AWS managed best practices
- **Lower TCO vs Managed Node Groups** while maintaining Kubernetes conformance
- **Integrated scaling and optimization** reducing operational overhead
Cost Comparison:
- Traditional EKS management requires dedicated DevOps resources
- Auto Mode reduces operational costs through automation
- Built-in cost optimization reduces compute waste
5. Reserved Capacity & Savings Plans
When to Use Reserved Capacity:
- Predictable container workloads running 24/7
- Stable cluster sizes with consistent resource requirements
- Long-term application deployments (1-3 years)
Savings Plans for Containers:
- **Compute Savings Plans:** Apply to Fargate, EC2, and Lambda
- **EC2 Instance Savings Plans:** Specific to EC2-based container deployments
- **Flexible usage:** Plans apply across different container services
Analysis Commands:
// Check Savings Plans coverage for containers
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "sp_performance", {
"operation": "get_savings_plans_coverage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\", \"Amazon Elastic Container Service for Kubernetes\"]}}"
})
---
Common Cost Pitfalls & Solutions
Pitfall 1: Over-Provisioned Resources
Problem Description:
- Setting CPU/memory requests much higher than actual usage
- Results in wasted capacity and higher costs
- Common in initial deployments without proper monitoring
Detection:
// Identify resource utilization patterns
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "ContainerInsights",
"metric_name": "pod_cpu_utilization",
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 3600,
"statistics": ["Average", "Maximum"]
})
Solution:
- Use Kubecost to identify slack cost (unused requested resources)
- Implement Vertical Pod Autoscaler for automatic right-sizing
- Regular review of resource requests vs actual usage
- Set up monitoring dashboards for resource efficiency
Pitfall 2: Inefficient Scaling Configuration
Problem Description:
- Scaling too aggressively or not aggressively enough
- Using wrong metrics for scaling decisions
- Not implementing proper scale-down policies
Detection & Solution:
- Monitor scaling events and their cost impact
- Use appropriate metrics (requests/second vs CPU utilization)
- Implement predictive scaling for known patterns
- Configure proper cooldown periods to avoid thrashing
Pitfall 3: Ignoring Data Transfer Costs
Problem Description:
- Cross-AZ communication between containers
- Inefficient service mesh configurations
- Not co-locating related services
Detection & Solution:
- Monitor data transfer costs in Cost Explorer
- Use topology-aware routing in service meshes
- Implement proper service placement strategies
- Consider regional deployment patterns
---
Real-World Scenarios
Scenario 1: Microservices Cost Optimization
Situation:
- Company with 50+ microservices running on EKS
- High control plane costs ($3,600/month for 50 clusters)
- Inconsistent resource utilization across services
Analysis Approach:
// Step 1: Analyze current EKS costs
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service for Kubernetes\"]}}"
})
// Step 2: Get container optimization recommendations
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "compute_optimizer", {
"operation": "get_ecs_service_recommendations"
})
// Step 3: Analyze resource utilization
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "get_metric_statistics", {
"namespace": "ContainerInsights",
"metric_name": "cluster_cpu_utilization",
"start_time": "2024-11-01T00:00:00Z",
"end_time": "2024-12-01T00:00:00Z",
"period": 3600,
"statistics": ["Average"]
})
Solution Implementation:
- Consolidated from 50 clusters to 10 multi-tenant clusters
- Implemented Kubecost for per-service cost allocation
- Used kube-downscaler for development environment cost reduction
- Migrated appropriate workloads to Fargate for better cost predictability
Results:
- **60% reduction in control plane costs** ($3,600 → $1,440/month)
- **25% overall container cost reduction** through right-sizing
- **Improved resource utilization** from 30% to 65% average
Scenario 2: Batch Processing Optimization
Situation:
- Data processing company running batch jobs on ECS
- Highly variable workloads with peak processing times
- High costs during peak periods, idle resources during off-peak
Analysis Approach:
// Analyze batch processing patterns
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "HOURLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\"]}}"
})
Solution Implementation:
- Migrated batch jobs to Fargate for pay-per-use model
- Implemented Spot instances for fault-tolerant batch processing
- Used scheduled scaling for predictable workload patterns
- Optimized container images for faster startup times
Results:
- **70% cost reduction** during off-peak hours
- **40% overall cost savings** through Spot instance usage
- **Improved processing efficiency** with optimized container images
---
Integration with Other Services
Cost Impact of Service Integrations
Common Integration Patterns:
- **EKS + ALB:** Application Load Balancer costs for service exposure
- **ECS + RDS:** Database connectivity and data transfer considerations
- **Containers + S3:** Storage costs for application data and logs
- **Service Mesh:** Additional overhead but improved observability
Cross-Service Optimization:
- **Regional co-location:** Minimize data transfer costs between services
- **Shared resources:** Use shared ALBs, NAT gateways, and VPC endpoints
- **Storage optimization:** Use EFS for shared storage across containers
Analysis Commands:
// Analyze cross-service container costs
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_explorer", {
"operation": "getCostAndUsage",
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"granularity": "MONTHLY",
"group_by": "[{\"Type\": \"DIMENSION\", \"Key\": \"SERVICE\"}]",
"metrics": "[\"UnblendedCost\"]",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\", \"Amazon Elastic Container Service for Kubernetes\", \"Amazon Elastic Load Balancing\", \"Amazon Relational Database Service\"]}}"
})
---
Monitoring & Alerting
Key Metrics to Monitor
Cost Metrics:
- Daily container spend by service and cluster
- Cost per container hour and cost per request
- Resource efficiency ratios (actual vs requested resources)
Usage Metrics:
- CPU and memory utilization across clusters
- Pod/task scaling events and their triggers
- Spot instance interruption rates and handling
Operational Metrics (via CloudWatch Container Insights):
- Cluster-level resource utilization
- Service-level performance metrics
- Container startup and termination patterns
Recommended Alerts
Budget Alerts:
// Monitor container-specific budget performance
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "budgets", {
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\", \"Amazon Elastic Container Service for Kubernetes\"]}}"
})
Anomaly Detection:
// Set up anomaly monitoring for container services
usePower("aws-cost-optimization", "awslabs.billing-cost-management-mcp-server", "cost_anomaly", {
"start_date": "2024-11-01",
"end_date": "2024-12-01",
"filters": "{\"Dimensions\": {\"Key\": \"SERVICE\", \"Values\": [\"Amazon Elastic Container Service\", \"Amazon Elastic Container Service for Kubernetes\"]}}"
})
Operational Alerts:
// Monitor container-related operational alarms
usePower("aws-cost-optimization", "awslabs.cloudwatch-mcp-server", "describe_alarms", {
"alarm_name_prefix": "Container",
"state_value": "ALARM"
})
Third-Party Monitoring Tools
Kubecost Integration:
- Real-time cost allocation and optimization recommendations
- Integration with Prometheus and Grafana
- Cost allocation by Kubernetes primitives
Other Tools:
- **Datadog:** Container monitoring with cost correlation
- **Splunk:** Log aggregation and cost analysis
- **Amazon Managed Prometheus/Grafana:** Native AWS monitoring stack
---
Best Practices Summary
✅ Do:
- **Use Spot instances** - Up to 90% savings with proper termination handling
- **Implement proper resource requests** - Right-size CPU/memory based on actual usage
- **Consolidate clusters** - Reduce control plane costs through multi-tenancy
- **Use auto-scaling** - Scale both applications and infrastructure dynamically
- **Monitor with Kubecost** - Get detailed cost allocation and optimization insights
❌ Don't:
- **Over-provision resources** - Monitor actual usage and adjust requests accordingly
- **Ignore data transfer costs** - Consider service placement and communication patterns
- **Run development clusters 24/7** - Use kube-downscaler for off-hours cost reduction
- **Use only on-demand instances** - Mix with Spot instances for cost optimization
- **Neglect image optimization** - Optimize container images for size and performance
🔄 Regular Review Cycle:
- **Daily:** Monitor resource utilization and scaling events
- **Weekly:** Review cost anomalies and optimization opportunities
- **Monthly:** Analyze cost trends and right-sizing recommendations
- **Quarterly:** Review cluster architecture and consolidation opportunities
---
Additional Resources
AWS Documentation
- [EKS Cost Monitoring](https://docs.aws.amazon.com/eks/latest/userguide/cost-monitoring.html)
- [ECS Cost Optimization](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-recommendations.html)
- [Fargate Pricing](https://aws.amazon.com/fargate/pricing/)
Tools & Calculators
- [Kubecost](https://www.kubecost.com/) for EKS cost monitoring
- [kube-resource-report](https://github.com/hjacobs/kube-resource-report) for resource utilization analysis
- [AWS Node Termination Handler](https://github.com/aws/aws-node-termination-handler) for Spot instance management
Related Power Guidance
- EC2 AMD Cost Optimization for underlying compute optimization
- Storage Cost Optimization for persistent volume strategies
- Lambda Cost Optimization for serverless container alternatives
---
Service Codes: AmazonECS, AmazonEKS, AWSFargate
Last Updated: January 2026
Review Cycle: Quarterly