Bird
Raised Fist0
AWScloud~10 mins

ECS with ALB integration in AWS - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an ECS cluster.

AWS
resource "aws_ecs_cluster" "example" {
  name = "[1]"
}
Drag options to blanks, or click blank then click option'
Amy-ecs-cluster
Becs-cluster-1
Cexample-cluster
Dcluster-ecs
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the name blank or using invalid characters.
Using a name that conflicts with existing resources.
2fill in blank
medium

Complete the code to create an Application Load Balancer (ALB).

AWS
resource "aws_lb" "app_alb" {
  name               = "app-alb"
  internal           = false
  load_balancer_type = "[1]"
  subnets            = var.subnet_ids
}
Drag options to blanks, or click blank then click option'
Anetwork
Bapplication
Cgateway
Dclassic
Attempts:
3 left
💡 Hint
Common Mistakes
Using "network" or "classic" instead of "application".
Leaving the load_balancer_type undefined.
3fill in blank
hard

Fix the error in the ECS task definition to specify the container port mapping.

AWS
container_definitions = jsonencode([
  {
    "name": "web",
    "image": "nginx",
    "portMappings": [
      {
        "containerPort": [1],
        "hostPort": 0,
        "protocol": "tcp"
      }
    ]
  }
])
Drag options to blanks, or click blank then click option'
A22
B8080
C443
D80
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 22 which is for SSH, not web traffic.
Using port 443 which is for HTTPS but nginx defaults to 80.
4fill in blank
hard

Fill both blanks to define a listener and target group for the ALB.

AWS
resource "aws_lb_target_group" "app_tg" {
  name     = "app-tg"
  port     = [1]
  protocol = "[2]"
  vpc_id   = var.vpc_id
}
Drag options to blanks, or click blank then click option'
A80
B443
CHTTP
DHTTPS
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing port 443 with HTTP protocol.
Using HTTPS protocol without proper certificates.
5fill in blank
hard

Fill all three blanks to configure the ECS service with ALB integration.

AWS
resource "aws_ecs_service" "app_service" {
  name            = "app-service"
  cluster         = aws_ecs_cluster.example.id
  task_definition = aws_ecs_task_definition.app_task.[1]
  desired_count   = 2
  launch_type     = "FARGATE"

  network_configuration {
    subnets         = var.subnet_ids
    security_groups = [aws_security_group.app_sg.id]
    assign_public_ip = true
  }

  load_balancer {
    target_group_arn = aws_lb_target_group.app_tg.[2]
    container_name   = "web"
    container_port   = [3]
  }
}
Drag options to blanks, or click blank then click option'
Aarn
Bid
C80
Drevision
Attempts:
3 left
💡 Hint
Common Mistakes
Using task definition ARN instead of revision.
Using target group ID instead of ARN.
Setting container port to wrong value.

Practice

(1/5)
1. What is the main purpose of integrating an Application Load Balancer (ALB) with Amazon ECS?
easy
A. To distribute incoming web traffic evenly across multiple container tasks
B. To store container images securely
C. To monitor CPU usage of ECS tasks
D. To create virtual private clouds automatically

Solution

  1. Step 1: Understand ALB role in ECS

    ALB is designed to balance incoming traffic to multiple targets, such as ECS tasks, to ensure reliability and scalability.
  2. Step 2: Identify the correct purpose

    Among the options, only distributing web traffic evenly matches ALB's function in ECS.
  3. Final Answer:

    To distribute incoming web traffic evenly across multiple container tasks -> Option A
  4. Quick Check:

    ALB balances traffic = C [OK]
Hint: ALB balances traffic to containers, not stores or monitors [OK]
Common Mistakes:
  • Confusing ALB with container image storage
  • Thinking ALB monitors CPU usage
  • Assuming ALB creates VPCs
2. Which ECS launch type and network mode combination is recommended for simple networking and security when using ALB?
easy
A. EC2 launch type with none network mode
B. EC2 launch type with bridge network mode
C. Fargate launch type with host network mode
D. Fargate launch type with awsvpc network mode

Solution

  1. Step 1: Recall recommended ECS and network mode

    Fargate with awsvpc mode provides each task with its own network interface, simplifying networking and security.
  2. Step 2: Match options to recommendation

    Only Fargate launch type with awsvpc network mode matches the recommended combination for ALB integration.
  3. Final Answer:

    Fargate launch type with awsvpc network mode -> Option D
  4. Quick Check:

    Fargate + awsvpc = A [OK]
Hint: Fargate + awsvpc = simple networking with ALB [OK]
Common Mistakes:
  • Choosing EC2 launch type instead of Fargate
  • Using bridge or host network modes with Fargate
  • Selecting none network mode which disables networking
3. Given this ECS service configuration snippet, what will happen when the ALB receives HTTP requests?
{
  "loadBalancers": [{
    "targetGroupArn": "arn:aws:elasticloadbalancing:...",
    "containerName": "webapp",
    "containerPort": 80
  }],
  "launchType": "FARGATE",
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": ["subnet-12345"],
      "assignPublicIp": "ENABLED"
    }
  }
}
medium
A. ALB forwards requests to the webapp container on port 80 in each task
B. ALB blocks all HTTP requests due to missing security group
C. ALB forwards requests to port 443 by default
D. ALB cannot route because containerPort is missing

Solution

  1. Step 1: Analyze load balancer target settings

    The ALB targets the container named "webapp" on port 80, so it will forward HTTP requests there.
  2. Step 2: Check network configuration

    Fargate with awsvpc and public IP enabled allows tasks to receive traffic from ALB.
  3. Final Answer:

    ALB forwards requests to the webapp container on port 80 in each task -> Option A
  4. Quick Check:

    ALB targets container port 80 = B [OK]
Hint: ALB forwards to specified containerPort, not default 443 [OK]
Common Mistakes:
  • Assuming ALB blocks traffic without explicit security group mention
  • Thinking ALB defaults to port 443
  • Missing containerPort causes routing failure
4. You deployed an ECS service with ALB integration but the ALB shows no healthy targets. What is the most likely cause?
medium
A. The ECS cluster has no EC2 instances running
B. The ALB listener is missing a rule for HTTPS traffic
C. The ECS tasks are not registering with the target group due to incorrect container port mapping
D. The ALB is in a different AWS region than the ECS service

Solution

  1. Step 1: Understand why ALB shows no healthy targets

    ALB health checks fail if ECS tasks do not register correctly, often due to wrong container port mapping.
  2. Step 2: Evaluate other options

    Listener rules missing HTTPS won't cause no healthy targets; ECS Fargate doesn't need EC2 instances; ALB and ECS must be in same region, but this is less common cause.
  3. Final Answer:

    The ECS tasks are not registering with the target group due to incorrect container port mapping -> Option C
  4. Quick Check:

    Incorrect port mapping blocks target registration = A [OK]
Hint: Check container port matches target group port for healthy targets [OK]
Common Mistakes:
  • Assuming missing HTTPS rule causes no healthy targets
  • Thinking ECS Fargate needs EC2 instances
  • Ignoring region mismatch issues
5. You want to deploy a highly available ECS service behind an ALB that automatically scales with traffic. Which combination of settings ensures this best practice?
hard
A. Use EC2 launch type with none mode, ALB with health checks disabled, and ECS service with fixed task count
B. Use Fargate launch type with awsvpc mode, ALB with target group health checks, and ECS service auto scaling
C. Use Fargate launch type with host mode, ALB with fixed target group size, and no ECS scaling
D. Use EC2 launch type with bridge mode, ALB without health checks, and manual ECS task scaling

Solution

  1. Step 1: Identify best ECS launch and network mode for availability

    Fargate with awsvpc mode simplifies networking and security, ideal for high availability.
  2. Step 2: Confirm ALB and ECS scaling features

    ALB target group health checks ensure traffic only goes to healthy tasks; ECS service auto scaling adjusts task count with traffic.
  3. Step 3: Evaluate other options

    Other options lack health checks or auto scaling, reducing availability and scalability.
  4. Final Answer:

    Use Fargate launch type with awsvpc mode, ALB with target group health checks, and ECS service auto scaling -> Option B
  5. Quick Check:

    Fargate + awsvpc + ALB health checks + auto scaling = D [OK]
Hint: Combine Fargate, awsvpc, ALB health checks, and auto scaling [OK]
Common Mistakes:
  • Skipping ALB health checks
  • Using manual scaling instead of auto scaling
  • Choosing EC2 with bridge or none network modes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard