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개 답변
1
수락된 답변

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
답변함 일 년 전
  • Thanks for the quick answer. After some experimentation, I was able to solve the issue.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠