Terraform AWS ECS Alb Service Task

Terraform module which implements an ECS service which exposes a web service via ALB.

Blockchain & Cloud ComputingHCLApache-2.0

Abstract

Terraform AWS ECS Alb Service Task is an open-source Blockchain & Cloud Computing project. Terraform module which implements an ECS service which exposes a web service via ALB. The container_definition is a string of JSON-encoded container definitions. Normally, you would place only one container definition here as the example above demonstrates. It is built using HCL, Terraform, Docker. The complete source code is publicly available on GitHub under the Apache License 2.0, making it a useful reference for students building a Blockchain & Cloud Computing mini project or final-year project.

1. Introduction

The container_definition is a string of JSON-encoded container definitions. Normally, you would place only one container definition here as the example above demonstrates. However, there might be situations where more than one container per task is more appropriate such as optionally in Fargate or in other cases where sidecars may be required. With cloudposse/terraform-aws-ecs-container-definition multi-container task definitions can be created using: Refer to the multiple definitions example in cloudposse/terraform-aws-ecs-container-definition for details on defining multiple definitions.

Terraform module to create an ECS Service for a web app (task), and an ALB target group to route requests.

forward action referencing BOTH the primary and alternate target groups (ECS shifts the weights during a deployment — start the alternate at weight 0), and role_arn must be an IAM role that ECS can assume with the AWS-managed AmazonECSInfrastructureRolePolicyForLoadBalancers policy. See examples/blue-green for a full, working setup. Only the ROLLING and BLUE_GREEN strategies are currently supported.

2. Objective

Terraform module which implements an ECS service which exposes a web service via ALB.

This project demonstrates how HCL, Terraform, Docker can be applied to a real-world Blockchain & Cloud Computing problem.

4. Technology Stack

HCLTerraformDocker

5. System Requirements

General requirements for this technology stack — check the README for exact versions.

  • Terraform CLI
  • Cloud provider account (e.g. AWS) with CLI configured
  • Git (to clone the repository)

6. Installation & Setup

git clone https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git
cd terraform-aws-ecs-alb-service-task
module "ecs_alb_service_task" {
  source = "cloudposse/ecs-alb-service-task/aws"
  # ... other configuration ...

  deployment_configuration = {
    strategy             = "BLUE_GREEN"
    bake_time_in_minutes = 3
  }

  ecs_load_balancers = [
    {
      container_name   = var.container_name
      container_port   = 80
      target_group_arn = module.alb.default_target_group_arn # production ("blue") target group
      advanced_configuration = {
        alternate_target_group_arn = aws_lb_target_group.alternate.arn      # "green" target group
        production_listener_rule   = aws_lb_listener_rule.blue_green.arn
        role_arn                   = aws_iam_role.ecs_blue_green.arn         # AmazonECSInfrastructureRolePolicyForLoadBalancers
      }
    }
  ]
}
module "ecs_alb_service_task" {
  ...
  container_definition_json = jsonencode([
    module.first_container.json_map_object,
    module.second_container.json_map_object,
  ])
  ...
}

Full setup instructions are in the project README.

7. Future Enhancements

Suggested extensions you can add to make this your own project.

  • Add a CI/CD pipeline with GitHub Actions
  • Deploy to a public test network or cloud free tier
  • Add monitoring and cost alerts

8. Viva / Review Questions

Common questions examiners ask for projects in this domain.

  1. Why does this problem need a blockchain or cloud-native design?
  2. Explain the smart contract / infrastructure components and how they interact.
  3. How are gas costs or cloud costs kept under control?
  4. How is the system secured (keys, IAM, access control)?
  5. How would the solution scale to many more users?

9. Source Code & License

This project is developed by cloudposse and published on GitHub under the Apache License 2.0. Please follow the license terms and credit the original author when you use or modify this code.

Want to build this as your internship project?

Work on a Blockchain & Cloud Computing project like this with mentor guidance, weekly reviews and an internship certificate from Training Trains, Erode — online or offline.

Apply for Blockchain & Cloud Computing Internship