To update a ECS service using script you can use the below command
Parameters required
- Cluster Name
- Service Name
aws ecs update-service --cluster ecsdeployment --service ecsdeployment-WebService-voWNHfK05HHq --force-new-deployment --region us-east-1
In some cases, this command didn’t update the service and if you need to run just one container for your service and you can have downtime then update your service as shown below :
Automation
You can easily automate this process from your pipeline. Create a shell script and run these commands
- You need to use the login command to push the images in ECR
- Build, tag and publish
- Update the service
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin xxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.comdocker build -t XXXXX -f Dockerfile.nginx . --no-cachedocker tag XXXXX:latest XXXXXXX.dkr.ecr.us-east-1.amazonaws.com/XXXXX:latestsudo docker push XXXXXX.dkr.ecr.us-east-1.amazonaws.com/XXXX:latestaws ecs update-service --cluster ecsdeployment --service ecsdeployment-WebService-AP1WCLw9qhgn --force-new-deployment --region us-east-1