I have set up an AWS CodePipeline stack using the CDK Pipelines module. When the code is pushed to the backing CodeCommit repo, the pipeline starts executing and does the following:
All of this is working fine.
But every time I push to the repo, I expect the Fargate Service to be updated with the latest docker image. This is not happening. The Fargate Service is not updated and the tasks within the service continue to run using the docker image that was latest at the time of creating the Fargate Service.
How do I make the Fargate Service update i.e. start new tasks with the latest image and shut down existing tasks with the old image?
If I run the following command manually from the command line then the service updates i.e. start new tasks with the latest image and shut down existing tasks with the old image.
aws ecs update-service --cluster CLUSTER_NAME --service SERVICE_NAME --force-new-deployment
You would do the same thing you do manually, but in the pipeline. Add a CodeBuildStep that executes the command after the deployment.
Alternatively, you could use assets and let the pipeline handle the building and ECR uploading.
For ECS, you'd use ContainerImage.fromDockerImageAsset()
.
This will update the Task definition with the new tag, which will force redeployment.