I have provided application configuration via consul's key-value store to the application containers running in ECS services.
The application reads its configuration from consul only once on start up.
When I need to change the configuration, how should I go about restarting the containers so that the application configuration is refreshed?
I am hoping to do this programmatically via the aws cli.
To reboot an instance using the consoleOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances. Select the instance and choose Instance state, Reboot instance.
You can use the docker ps command on your container instance to list the running containers. In the below example, only the Amazon ECS container agent is running. For more information, see docker ps in the Docker documentation.
You don't restart containers. You can however stop the individual tasks, and ECS will respawn another instance of your task somewhere on the cluster.
As @Aidin mentioned, you can achieve it via the AWS CLI by forcing a new deployment like so:
aws ecs update-service \
--service <service name> \
--cluster <cluster name> \
--force-new-deployment \
[--profile guestapi-dev]
Note that this does not work on services with a CodeDeploy deployment controller.
I faced the same challenge, and what I did was follow this guide (using the old or new console depending on your service). I don't know if this can be done via the CLI, but it does actually "restart the service" in that it re-spawns new task(s) for your service and kills the old one(s).
In summary:
In the old console:
In the new console:
The service will re-deploy. You should be able to see the existing task(s) running, the new task(s) provision and lastly the old task(s) disappear.
this worked for me:
aws ecs list-tasks --cluster my-cluster-name | jq -r ".taskArns[]" | awk '{print "aws ecs stop-task --cluster my-cluster-name --task \""$0"\""}' | sh
Go to ECS dashboard. Just stop the running task from your ECS service from aws console. it'll spawn a new task and terminate the old one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With