This solution provides a comprehensive, automated approach to optimize costs across multiple AWS services using AWS Compute Optimizer. It includes optimization for:
- EC2 Instances
- EC2 Auto Scaling Groups
- RDS Instances
- Lambda Functions
The solution uses AWS Compute Optimizer's machine learning-powered recommendations to automatically identify and implement cost-saving opportunities while maintaining performance.
If you want to deploy only specific optimizer component, then go to the respective folder and follow the README file.
-
AWS Compute Optimizer
- Analyzes utilization metrics
- Provides instance type recommendations
- Supports multiple resource types
-
AWS Lambda Functions
- Fetches recommendations from Compute Optimizer
- Updates SSM Parameters with recommendations
- Implements recommended changes
-
Amazon EventBridge
- Schedules regular optimization checks
- Triggers updates based on parameter changes
-
AWS Systems Manager Parameter Store
- Stores optimization recommendations
- Maintains history of changes
- Enables easy integration with IaC
-
AWS CloudFormation
- Deploys all components
- Manages infrastructure as code
- Handles updates and deletions
- AWS Account with appropriate permissions
- AWS CLI installed and configured
- AWS Compute Optimizer enabled in your account
- Python 3.8 or later
- Sufficient IAM permissions to create:
- IAM Roles and Policies
- Lambda Functions
- EventBridge Rules
- SSM Parameters
-
Enable AWS Compute Optimizer:
aws compute-optimizer update-enrollment-status --status Active
-
Deploy the CloudFormation Stack:
aws cloudformation create-stack \ --stack-name aws-cost-optimizer \ --template-body file://templates/aws-cost-optimizer-template.yml \ --capabilities CAPABILITY_NAMED_IAM
-
Monitor Stack Creation:
aws cloudformation describe-stacks \ --stack-name aws-cost-optimizer \ --query 'Stacks[0].StackStatus'
-
Clone the Repository:
git clone https://github.com/zechariahks/aws-cost-optimizer-solution cd aws-cost-optimizer
-
Review and Customize Parameters:
- Open
templates/aws-cost-optimizer-template.yml
- Adjust the following parameters as needed:
- Schedule expressions for optimization checks
- Lambda function timeouts and memory
- Resource naming conventions
- Open
-
Deploy the Stack:
Using AWS Console:
- Open CloudFormation console
- Click "Create stack"
- Upload template file
- Follow the wizard steps
Using AWS CLI:
aws cloudformation create-stack \ --stack-name aws-cost-optimizer \ --template-body file://templates/aws-cost-optimizer-template.yml \ --capabilities CAPABILITY_NAMED_IAM \ --parameters \ ParameterKey=OptimizerScheduleExpression,ParameterValue="rate(1 day)"
Once the deployment is complete, depending on when the Cost Optimization status became active in the account, it takes around 24 hours to generate recommendations. Event Bridge rules are scheduleed to run daily at once. Lambda functions will be invoked on this schedule and update the resource configurations as per the Compute Optimizer recommendations.
-
Delete the CloudFormation Stack:
aws cloudformation delete-stack --stack-name unified-cost-optimizer aws cloudformation wait stack-delete-complete --stack-name unified-cost-optimizer
-
Clean Up SSM Parameters:
# Remove all optimization parameters aws ssm get-parameters-by-path --path "/cost-optimizer" --recursive | \ jq -r '.Parameters[].Name' | \ while read param; do aws ssm delete-parameter --name "$param" done
-
Implementation:
- Deploy in test environment first
- Use gradual rollout strategy
- Implement proper monitoring
- Document all configurations
- Use resource tagging
-
Security:
- Follow least privilege principle
- Encrypt sensitive data
- Implement error handling
- Regular security audits
- Monitor API calls
-
Operations:
- Regular backup of configurations
- Monitor performance metrics
- Set up alerting
- Document procedures
- Test rollback processes
-
Cost Management:
- Monitor optimization savings
- Review recommendations regularly
- Set up cost allocation tags
- Implement budget alerts
- Clean up unused resources
-
Common Issues:
- Compute Optimizer not enabled
- Insufficient IAM permissions
- Lambda timeout issues
- Parameter Store throttling
- Resource modification failures
-
Resolution Steps:
- Check CloudWatch Logs
- Verify IAM roles
- Monitor service quotas
- Review error messages
- Check service health
For issues and feature requests:
- Open an issue in the GitHub repository
- Provide detailed description
- Include error messages
- Share relevant logs
- Describe expected behavior
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.