Continuous deployments with AWS ECS, Terraform and Jenkins (task definition revisions)

Jack Mahoney
Sep 25, 2018 · 1 min read

Here’s a quick and easy way to integrate continuously updated task definition deployments on AWS ECS with Terraform and Jenkins.

Preparation

This approach assumes that you have setup an ECS cluster, service and task definition defined in Terraform and output various variables for use in the application’s build pipeline. An example of the infrastructure setup in Terraform might be as follows.

Build your application docker image

Assuming that we have a Terraform setup like the above, lets build and deploy our docker image to the ECR docker repository. I fetch the repository URL and some other arguments that are baked into the docker image via Terraform output commands that fetch values from the infrastructure remote state.

Create a task definition and update service

Now that we have built and pushed a docker image for this build we need to create a new task revision for the ECS service and tell it to run. You could simply use latest as the image tag in your ECS task definition but I prefer explicit versioning. To do so we first use the register-task-definition command and then update-service .

Written by

My personal programming and development blog. More at https://dev.jackmahoney.me

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade