DEV Community

Revathi Joshi for AWS Community Builders

Posted on

6-part series - (2) Create Task Definition in ECS and Application Load balancer for the Task to be run on Fargate Cluster

In this 6-part series on configuring a CI/CD pipeline using Customized Docker image on an Apache Web Server, Application Load Balancer, ECS, ECR, CodeCommit, CodeBuild, CodeDeply services -

In the 2nd article, We will create Task Definition in ECS, that references the customized image my_apache_image in the repository - and Application Load balancer (ALB) for the Task which is to be run on Fargate Cluster.

1st article

Let’s get started!

Please visit my GitHub Repository for CI-CD/Docker/ECS/ECR articles on various topics being updated on constant basis.

Objectives:

1. Create role

2. Create Task definition

3. Create an Application Load Balancer (ALB) and Target groups

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • AWS CLI.

Resources Used:

Amazon ECS task definitions

Application Load Balancer

Steps for implementation to this project:

1. Create role

  • On the EC2 dashboard, Roles, Create role, Use cases - EC2, Next, Search for AmazonECSTaskExecutionRolePolicy, AmazonECSTaskExecutionRole

  • Create role

Image description

  • click AmazonECSTaskExecutionRole, Trust relationships, Edit Trust policy, delete the default code and copy and paste this policy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "ecs-tasks.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode
  • Update policy

Image description

2. Create Task definition

  • on Elastic Container Service in the Containers section, Task definitions, Create new Task Definition, my_task, Under Container details, my_container

From my 1st article, Step-7, Copy image URI -
<YOUR ACCOUNT NUMBER>.dkr.ecr.us-east-1.amazonaws.com/my-ecr:latest

  • Next, Fargate, Under Task size, choose Task memory as 0.5 GB and Task CPU as 0.25 vCPU, Task execution role - ecsTaskExecutionRole is selected automatically, Next

  • Create

Image description

  • Task definition - my_task

Image description

  • Container name - my_container

Image description

3. Create an Application Load Balancer (ALB) and Target groups

  • On EC2 Dashboard, Load Balancers, Create load balancer
    Application load Balancer, Create, my-alb, internet-facing, default vpc, 2 public subnets - us-east-1a and us-east-1b,
    my_sg (Security group of EC2 Instance)

  • create target group, instances, my-tg, Next, Available instances, DO NOT SELECT EC2 INSTANCE, Create target group

  • On Load balancer page, refresh, select my-tg

  • Create Load Balancer

Image description

Target Groups

Image description

What we have done so far

  • We have successfully created
  • (1) Task Definition in ECS that references the customized image in the repository and
  • (2) Application Load balancer (ALB) for the Task which is to be run on Fargate Cluster.

Top comments (1)

Collapse
 
andrewbrown profile image
Andrew Brown πŸ‡¨πŸ‡¦

The most important part of this articlec is creating the Task Defintion and there are no details listed here. I would expand on this section.