CodePipeline + ECS deploy: deregister, drain, stop?


hi everyone,

I've got a CodePipeline + ECS question: we have a pipeline configured to do source --> build --> deploy that uses in the final step an Amazon ECS Deploy action provider like so:

Enter image description here

My expectation, from reading on the internet ( and, is that when a new deployment happens in ECS, that it should:

  • deregister the old task
  • drain the old tasks... then
  • stop the old tasks

but when I'm seeing is that my containers are getting a "stop" message first... then deregister happens... then draining happens, which is problematic for our JVM's because the stop command / message tells the JVM to start shutting down... but we haven't drained the connections yet.

Anyone have any experience / tips for getting drain + degister happening well before a stop message is issued to the containers?

2 Answers

Hi, if you want to have good control of what happens at JVM shutdown triggered by ECS to drain your sessions and do other things for a clean shutdown, you should insert shutdown hooks in your JVM config.


With such hooks in place, you can do what you need: wait for existing sessions to complete, etc. before proceeding to effective shutdown



profile pictureAWS
answered a year ago

yeah, that doesn't really help... the application I have is constantly receiving new HTTP requests.... I need ECS to stop sending requests / drain connections... THEN tell the JVM after all the connections are drained to stop...

Am I wrong that the ECS process should be 1) deregister, 2) drain, 3) shutdown?

profile picture
answered a year ago

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