articles / ecs-spring-boot-spring-batch-vs-eks

ECS for Spring Boot and Spring Batch, compared with EKS

Mounir Guizani · 29 November 2026 · 4 min read

  • aws
  • ecs
  • eks
  • spring

On my AWS migration mission, part of the workload runs on Amazon ECS: Spring Boot APIs that answer continuously, and Spring Batch jobs that start, compute, then stop. Two very different profiles, one orchestrator. Here is how I deploy them, and why ECS rather than EKS in this context.

ECS in four words

  • Cluster: the logical grouping where containers run.
  • Task definition: the recipe for a container (image, CPU, memory, variables, secrets, IAM role, logs).
  • Task: a running instance of that recipe.
  • Service: ECS keeps N tasks alive at all times, replaces them if they fail, and attaches them to a load balancer.

The key distinction is between a service (long-running) and a standalone task (one-off run).

Case 1: a Spring Boot API as an ECS service

An API must always be available, so it runs as a service:

  • behind an Application Load Balancer, which checks health through /actuator/health;
  • with a rolling update: new tasks start and pass the health check before the old ones stop;
  • with auto scaling on CPU or requests per task.

Two settings that prevent many surprises:

  • a grace period on the health check, while Spring starts up;
  • a clean shutdown (server.shutdown=graceful) to finish in-flight requests during a redeployment.

Case 2: a Spring Batch job as a standalone task

A batch job has no business running as a service: it must start, process, stop, and report whether it succeeded. It runs as a standalone task (RunTask):

  • triggered on a schedule by EventBridge Scheduler, or orchestrated by Step Functions, which waits for the task to finish and chains the next step;
  • the container stops when the job ends: you only pay for the processing time;
  • the container's exit code reflects the job status, so the orchestrator can react to failures.
@SpringBootApplication
public class BatchApplication {
    public static void main(String[] args) {
        // The container's exit code reflects the Spring Batch job status
        System.exit(SpringApplication.exit(SpringApplication.run(BatchApplication.class, args)));
    }
}

Watch-outs:

  • the Spring Batch JobRepository needs a database (here RDS Aurora) to store state and allow restarts;
  • large volumes are split into partitions, processed in parallel by several tasks;
  • secrets (database passwords) come from Secrets Manager or SSM, injected by the task definition, never baked into the image.

The two IAM roles not to mix up

Role Used by For
Execution role the ECS agent pulling the image from ECR, reading secrets, writing logs
Task role your code calling S3, SQS, DynamoDB… with only the permissions needed

Each service has its own task role: an API doesn't get the batch's permissions, and vice versa.

ECS or EKS?

I've also worked with Kubernetes (a complete pre-production environment with Jenkins, Docker and Kubernetes at Société Générale). Both are good choices, for different contexts:

ECS EKS (Kubernetes)
Control plane included, no charge billed, about $73 per month per cluster
Learning curve short long (objects, networking, RBAC, upgrades)
AWS integration native (IAM per task, ALB, CloudWatch) through add-ons and controllers
Ecosystem AWS huge: Helm, operators, service mesh
Portability tied to AWS multi-cloud and on-premises
Batch jobs standalone tasks + EventBridge / Step Functions Jobs and CronJobs
Operations light a discipline of its own

My rule of thumb: ECS when the team wants to ship fast on AWS with little operational overhead. EKS when the organisation already has a Kubernetes platform, needs portability, or needs the ecosystem (operators, service mesh, standard tooling).

On a full AWS migration with a team of five, ECS delivers most of the benefits of containers without turning Kubernetes into a project of its own.

Learned on a missionCurrent engagement · AWS migration : Senior Java & AWS ConsultantSee the mission →