Deploying AWS ECS with Azure DevOps: A Step-by-Step Guide

Bebins V
4 min readOct 6, 2023

--

Amazon Elastic Container Service (ECS) is a powerful container orchestration service that simplifies the deployment, management, and scaling of Docker containers. In this guide, we’ll explore how to streamline the deployment process using Azure DevOps.

Build Steps

1. Build a Docker Image

The first step in our deployment pipeline is to build the Docker image for our application. This can be achieved using a Dockerfile. Ensure that your Dockerfile is present in the root of your project. Here’s an example Azure DevOps classic snippet for this task:

2. Push Image to ECR

After building the Docker image, the next step is to push it to the Amazon Elastic Container Registry (ECR). Configure your AWS credentials service connection.

3. Copy Files

Depending on your application, you might need to copy additional files or artifacts required for deployment. This step copies files from your source directory to the staging directory. Here we are copying the task definition file from the source code to the artifacts, which can be used to deploy the ecs service in the “Release step”

4. Publish Artifacts

Publish the required artifacts so that they can be used in the release pipeline.

The Following is the overall build configuration,

Release Steps

1. Replace Task Definition Token

In ECS, the task definition is a JSON file that describes the container and its settings. Before deploying to ECS, we need to replace tokens in our task definition file with the appropriate values. Here token pattern is important, remember to update based on your own format

Below is the sample content from the task definition variable configuration

          {
"name": "ASPNETCORE_ENVIRONMENT",
"value": "#{env}#"
}

2. Bash Script for ECS Task Definition Update

We’ll use a Bash script to update the ECS task definition with the new changes.

3. Bash Script for ECS Update Service

Lastly, use another Bash script to update the ECS service to use the new task definition.

Conclusion

By following these steps, you can create a robust deployment pipeline for your AWS ECS applications using Azure DevOps. This approach ensures a smooth and automated deployment process, allowing you to focus on building and improving your containerized applications.

Happy Coding!!!

--

--