← Back to list

Hybrid AWS Architecture: Mixing ECS and Lambda for Warm + Burst Processing

Introduction

AWS by a Solutions Architect · 2025-08-19 14:56 · 10 claps · 2.4 min read paywalled
#aws #archtecture #aws-ecs #aws-lambda #burst
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud 🏛️ · Architecture

Hybrid AWS Architecture: Mixing ECS and Lambda for Warm + Burst Processing

Introduction

Cloud workloads rarely fit into one neat box. Some jobs run constantly in the background, while others arrive in sudden spikes that overwhelm fixed capacity.

  • Amazon ECS (Fargate) is cost-effective for steady, predictable workloads but slower to react to sudden bursts.
  • AWS Lambda scales instantly, but isn’t cost-efficient for long-running or continuous jobs.

Solution? Combine them. Let ECS handle the warm, continuous load, and let Lambda kick in for burst traffic. This hybrid pattern delivers both economy and elasticity.

When to Use This Pattern

This architecture is ideal when:

  • You have background processing jobs (e.g., image resizing, video transcoding, PDF rendering).
  • Traffic includes sudden, unpredictable surges.
  • You want to avoid over-provisioning ECS just to handle rare peak loads.
  • You need SQS durability to avoid job loss during scaling.

High-Level Architecture

Hybrid AWS Architecture

Hybrid AWS Architecture

  • Producers send jobs (e.g., images, PDFs) to SQS.
  • ECS Fargate service consumes at a steady rate (cost-efficient baseline).
  • Lambda is subscribed to the same SQS, but scales up only when backlog grows.
  • CloudWatch Alarms adjust Lambda concurrency when queue length > threshold.
  • Processed outputs stored in S3 (or DynamoDB, RDS, etc.).

Step-by-Step Workflow

  1. Job enters SQS queue.
  2. ECS tasks pull jobs continuously, maintaining baseline processing.
  3. If queue backlog exceeds threshold:
  • CloudWatch Alarm triggers, increasing Lambda concurrency.
  • Lambda processes jobs in parallel, draining the queue quickly.
  1. Once backlog clears:
  • Lambda scales down to zero (no cost).
  • ECS continues steady work.

Infrastructure as Code (Terraform Example)

SQS Queue

resource "aws_sqs_queue" "job_queue" {
  name                       = "hybrid-job-queue"
  visibility_timeout_seconds = 300
}

ECS Baseline Service

resource "aws_ecs_task_definition" "ecs_task" {
  family                   = "ecs-worker"
  requires_compatibilities = ["FARGATE"]
  cpu                      = "512"
  memory                   = "1024"
  network_mode             = "awsvpc"

  container_definitions = jsonencode([{
    name      = "worker"
    image     = "123456789012.dkr.ecr.us-east-1.amazonaws.com/worker:latest"
    essential = true
    environment = [
      { name = "SQS_QUEUE_URL", value = aws_sqs_queue.job_queue.url }
    ]
  }])
}

resource "aws_ecs_service" "ecs_service" {
  name            = "ecs-worker-service"
  cluster         = aws_ecs_cluster.main.id
  task_definition = aws_ecs_task_definition.ecs_task.arn
  desired_count   = 2
  launch_type     = "FARGATE"
  network_configuration {
    subnets         = ["subnet-abc", "subnet-def"]
    assign_public_ip = true
  }
}

Lambda for Burst Loads

resource "aws_lambda_function" "spike_handler" {
  function_name = "spike-handler"
  handler       = "index.handler"
  runtime       = "nodejs18.x"
  role          = aws_iam_role.lambda_exec.arn
  timeout       = 300
  memory_size   = 1024

  environment {
    variables = {
      SQS_QUEUE_URL = aws_sqs_queue.job_queue.url
    }
  }
  filename = "lambda.zip"
}

resource "aws_lambda_event_source_mapping" "lambda_sqs" {
  event_source_arn = aws_sqs_queue.job_queue.arn
  function_name    = aws_lambda_function.spike_handler.arn
  batch_size       = 10
}

CloudWatch Alarm for Backlog

resource "aws_cloudwatch_metric_alarm" "queue_alarm" {
  alarm_name          = "sqs-backlog-high"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = 1
  metric_name         = "ApproximateNumberOfMessagesVisible"
  namespace           = "AWS/SQS"
  period              = 60
  statistic           = "Average"
  threshold           = 100
  dimensions = {
    QueueName = aws_sqs_queue.job_queue.name
  }
}

Benefits

Cost efficiency — ECS handles steady load cheaply. Instant scalability — Lambda kicks in for bursts. No job loss — SQS buffers requests during scaling. Unified workflow — Both ECS and Lambda consume from same queue.

Gotchas

Visibility Timeout — Must exceed max processing time to avoid duplicates. Deduplication — Ensure idempotent job processing. Cold Starts — Lambda still has cold starts, but only affects spikes (not baseline). Monitoring Costs — CloudWatch alarms and Lambda spikes can surprise if not tracked.

Conclusion

This hybrid ECS + Lambda model is a pragmatic balance:

  • ECS gives you the steady efficiency.
  • Lambda gives you burst elasticity.
  • SQS + CloudWatch ensure smooth orchestration.

It’s not “serverless vs containers” — it’s serverless + containers.


메타데이터
post_id
de3f0491b280
slug
hybrid-aws-architecture-mixing-ecs-and-lambda-for-warm-burst-processing-de3f0491b280
url
https://medium.com/@thecloudguru/hybrid-aws-architecture-mixing-ecs-and-lambda-for-warm-burst-processing-de3f0491b280
canonical_url
https://medium.com/@thecloudguru/hybrid-aws-architecture-mixing-ecs-and-lambda-for-warm-burst-processing-de3f0491b280
author_url
https://medium.com/@thecloudguru
status
ok
fetched_at
2026-06-24 18:57:25