WorkingDirectory icon
Clone icon
TerraformCLI icon
Script icon
Docker icon
Parallel icon
Commands icon
Batch icon

High-Performance Computing, Run Parallel Python Workloads on AWS Batch with ECS Fargate

Provision AWS Batch and ECS Fargate with Terraform, parse the outputs, and run parallel Python workloads on serverless compute, all in one Kestra flow.

Categories
CloudCoreInfrastructure

Run high-performance, massively parallel Python workloads on AWS Batch backed by ECS Fargate, with all the underlying cloud infrastructure provisioned automatically by Terraform. This blueprint closes the gap between infrastructure as code and compute orchestration: a single Kestra flow clones the Terraform definitions, applies them to stand up an AWS Batch compute environment, job queue, and ECS task roles, then immediately runs Python scripts on that freshly provisioned Batch backend. No manual server, cluster, or container management, and no copy-pasting ARNs between tools.

How it works

  1. A io.kestra.plugin.core.flow.WorkingDirectory task wraps the provisioning steps so cloned files and Terraform state stay together.
  2. io.kestra.plugin.git.Clone pulls the kestra-io/deployment-templates repository (branch main) containing the Terraform configuration for AWS Batch.
  3. io.kestra.plugin.terraform.cli.TerraformCLI injects a generated backend.tf (S3 remote state keyed on the bucket and region inputs), then runs terraform init, terraform apply -auto-approve, and writes terraform output to output.txt. AWS credentials and TF_VAR_* values are passed via env.
  4. io.kestra.plugin.scripts.python.Script (task parse_tf_output) reads output.txt and emits the Terraform outputs as Kestra outputs using the Kestra.outputs() SDK helper.
  5. io.kestra.plugin.core.flow.Parallel runs two Python tasks (run_command and run_python_script) at the same time, each using the io.kestra.plugin.ee.aws.runner.Batch task runner wired to the parsed computeEnvironmentArn, jobQueueArn, executionRoleArn, and taskRoleArn.

What you get

  • End-to-end provisioning of AWS Batch and ECS Fargate from version-controlled Terraform.
  • Secure remote Terraform state in an S3 backend.
  • Dynamic reuse of Terraform outputs (ARNs) as inputs to downstream compute tasks.
  • Parallel, serverless execution of Python workloads with no standing infrastructure.
  • A reproducible pattern you can fork for any compute-heavy job.

Who it's for

  • Data and platform engineers running compute-intensive Python on demand.
  • HPC and scientific computing teams needing elastic, ephemeral capacity.
  • Teams adopting infrastructure as code who want provisioning and execution in one pipeline.

Why orchestrate this with Kestra

Terraform provisions infrastructure but has no scheduler, no retries, and no built-in way to pass its outputs into a running compute job. Kestra adds event and schedule triggers, automatic retries, and full execution lineage across the provision-then-run sequence. Everything is declarative YAML, so the Git clone, the Terraform apply, the output parsing, and the parallel Batch jobs live in one auditable flow instead of being stitched together by hand.

Prerequisites

  • An AWS account with permissions to create Batch, ECS, IAM, and S3 resources.
  • An existing S3 bucket and region for the Terraform state backend (set via the bucket and region inputs).
  • The Enterprise Edition AWS Batch task runner (io.kestra.plugin.ee.aws.runner.Batch).

Secrets

  • AWS_ACCESS_KEY_ID: AWS access key for Terraform and the Batch task runner.
  • AWS_SECRET_KEY_ID: AWS secret access key for Terraform and the Batch task runner.

Quick start

  1. Add the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID secrets to your namespace or environment.
  2. Set the bucket and region inputs to match your S3 state backend.
  3. Execute the flow and watch Terraform provision Batch, then the parallel Python tasks run on ECS Fargate.

How to extend

  • Swap the demo Python scripts for your real workloads (data processing, model scoring, simulations).
  • Add more branches to the Parallel task or use ForEach to fan out over a list of inputs.
  • Point io.kestra.plugin.git.Clone at your own Terraform repository to provision different infrastructure.
  • Add a schedule or event trigger to provision and run on a cadence, then tear down with a follow-up terraform destroy.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.