ECS doesn't have away to schedule auto scaling for ECS service. You can use this lambda to schedule event to set desire count for your ECS service.
This could be used to stop and start your ECS services on schedule.
-
$ git clone https://github.com/XenonLab/aws-ecs-service-scaling-lambda.git
or download zip. -
Deploy to lambda function with your favorite method e.g. copy content of scaling.py to editor or upload zip to S3 bucket
-
Create custom Cloudwatch Event Rule with event defined as Constant (JSON text) and attach it to Lambda
{ "cluster": "mycluster", "service_name": "myservice", "service_desired_count": "1" }
-
Configure lambda
- Runtime: Python
- Handler:
lambda_function.scale_service
- Set & attach
role
to lambda function - Minimum role policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"ecs:UpdateService"
],
"Resource": "*"
}
]
}
- Define cloudwatch rule to set schudle for this lambda.