This Python utility is designed to upscale or downscale ECS (Amazon Elastic Container Service) services, providing functionality to manage containerized applications efficiently. It utilizes Boto3, the AWS SDK for Python, along with AWS Lambda functions.
-
Upscale and Downscale ECS Services: Automatically adjust the desired task count for ECS services based on specified criteria such as CPU or memory utilization.
-
Retrieve ECS Service Information: Obtain detailed information about ECS services including the number of tasks pending and running, aiding in monitoring and management.
-
Production Environment Protection: Implements safeguards to restrict updates to ECS services in production environments, minimizing risks and ensuring stability.
-
Cost Optimization: Efficiently manage ECS resources to optimize costs by scaling up or down based on demand, avoiding unnecessary expenses.
-
On-Demand Development and Staging Environments: Enable on-demand scaling for development and staging environments, allowing flexibility and agility in testing and development workflows.
There are two way to use this use this utility
1. Clone the repository and execute the utility as a standard Python project, allowing for customization and direct usage.
2. Configuration with AWS Lambda Function:
- AWS account with appropriate permissions to access ECS services.
- Lambda function with the appropriate IAM role.
- Postman for testing API endpoints.
- Set up a Lambda function with the provided IAM role.
{
"Effect": "Allow",
"Action": [
"ecs:ListServices",
"ecs:ListTasks",
"ecs:ListContainerInstances",
"ecs:ListTaskDefinitions",
"ecs:ListClusters",
"ecs:DescribeClusters",
"ecs:DescribeServices",
"ecs:DescribeTaskDefinition",
"ecs:DescribeTasks",
"ecs:UpdateService"
],
"Resource": "*"
}
- Attach an API Gateway to the Lambda function for external access. Consider implementing additional security measures such as API keys or IAM access.
- Utilize HTTP POST/GET requests to interact with the API Gateway endpoint.
- Provide the request body with parameters such as desired task count, cluster names, and environment details.
Example Request Body for Postman:
Use body object in case of Post man
{
"desired_tasks": "0",
"cluster_names": "all",
"environment" : "dev,stage"
}
To ensure safety and prevent unintended actions, the Prefix class has been implemented with specific keywords designated for different access levels.
ALLOWED: This includes a list containing only the wildcard '*', which essentially allows unrestricted access to all resources.
RESTRICTED: This list contains 'prod', indicating restricted access specifically to production resources.
to change the Constants.py you can chage safeguard
class Prefix(Enum):
ALLOWED = ['*']
RESTRICTED = ['prod']
The ECS Infrastructure Scaling Utility is a Python tool for automating ECS service scaling based on resource utilization. It offers monitoring features and safeguards for production environments, optimizing costs and enhancing flexibility.