Skip to content

s7anley/aws-ecs-service-stop-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

ECS Service Restart λ

ECS API currently does not allow users restart running services. Workaround is update service desired task to 0 and later update back with original value. Another solutions, used in this Lambda, stops underlying tasks associated with service. This will force scheduler to run new tasks.

How to use

  1. $ git clone https://github.com/s7anley/aws-ecs-service-stop-lambda.git or download zip.

  2. Deploy to lambda function with your favorite method e.g. copy content of main.py to editor or upload zip to S3 bucket

  3. Create custom Cloudwatch Event Rule with event defined as Constant (JSON text) and attach it to Lambda

    {
       "cluster": "mycluster",
       "service_name": "myservice"
    }
  4. Configure lambda

  • Runtime: Python
  • Handler: lambda_function.restart_service
  • Set & attach role to lambda function
  • Minimum role policy
 {
     "Version": "2012-10-17",
     "Statement": [
         {
             "Effect": "Allow",
             "Action": [
                 "ecs:ListTasks",
                 "ecs:StopTask",
             ],
             "Resource": "*"
         },
         {
             "Effect": "Allow",
             "Action": [
                 "logs:CreateLogGroup",
                 "logs:CreateLogStream",
                 "logs:PutLogEvents"
             ],
             "Resource": "*"
         }
     ]
 }

What about other event types?

Maybe this Lambda will fits you out-of-box, but it's just generic template which shows, how you can restart ECS service. You should adjust the code according your expected event e.g. S3 bucket name.

About

Simple AWS Lambda to restart ECS Services

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages