Updating an ECS service automatically using the CLI via Lambda

0

I have a multi-container application that runs a service on ECS. The images are hosted on ECR, configuration files are pulled from a S3 bucket during container startup via script. The application sits behind a network loadbalancer with EIP. The loadbalancer is in a public subnet and reachable, the app itself is inside a private subnet.

My ultimate goal is to automatically update the service when either a.) a new image is checked in or b.) a new configuration file is uploaded.

I figured the best way to do this behind a network load balancer (which supports rolling update) is to use the AWS ECS CLi inside a lambda function that triggers upon update. If I did not misread the docs, the CLI should trigger a rolling update. To test the CLI, I tried:

aws ecs update-service --cluster mycluster --service myservice --force-new-deployment

However, this was not successful. A new task was created, but was stopped before deployment was finished with log message:

Essential container in task exited

Parameters for the service are min. 100 % and max. 200 %. I also tried to set the lower bound of running tasks to 0 %. This resulted in the successful exit of the old task, but the new tasks failed to deploy with the same error. This makes me think that I probably configured something incorrectly.

Questions:

1.) Is using a lambda function a smart choice here? Or is there a better way?

2.) How can I troubleshoot the failing rolling update?

I appreciate any help! If you need more information, please let me know.

Best regards, Sebastian

1 Answer
1
Accepted Answer

This seems like it would work, specifically this makes sense from a config file on S3 perspective, as you can trigger the Lambda on upload. I would recommend checking out the docs here about creating requests to modify ECS[1]. It also contains reference requests in multiple languages using the AWS SDK. Eg here is a link for Javascript[2].

For troubleshooting the failed deployment, I'd recommend looking into CloudWatch logs[3][4].

[1]https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html

[2]https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECS.html#updateService-property

[3]https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_cloudwatch_logs.html

[4]https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-logging-monitoring.html

profile pictureAWS
answered a year ago
  • Thanks for the quick answer. After some experimentation, I was able to solve the issue.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions