Snakemake executor plugin: aws-batch-flex
Warning
This plugin is not maintained and reviewed by the official Snakemake organization.
Runs Snakemake workflows on AWS Batch with off-the-shelf
container images: each rule runs in the image its container: directive names, exactly as
published (quay.io/biocontainers, Docker Hub, ECR, …). You don’t build images with Snakemake
in them, and the images don’t need Python either: on EC2, a Snakemake environment baked into
the AMI is mounted into every job; on Fargate, Snakemake is installed when the job starts.
It needs Snakemake 9.5 or newer, and the S3 storage plugin (see below).
Installation
Install this plugin by installing it with pip or mamba directly, e.g.:
pip install snakemake-executor-plugin-aws-batch-flex
Or, if you are using pixi, add the plugin to your pixi.toml. Be careful to put it under the right dependency type based on the plugin’s availability, e.g.:
snakemake-executor-plugin-aws-batch-flex = "*"
Usage
In order to use the plugin, run Snakemake (>=8.6) in the folder where your workflow code and config resides (containing either workflow/Snakefile or Snakefile) with the corresponding value for the executor flag:
snakemake --executor aws-batch-flex --default-resources --jobs N ...
with N being the number of jobs you want to run in parallel and ... being any additional arguments you want to use (see below).
The machine on which you run Snakemake must have the executor plugin installed, and, depending on the type of the executor plugin, have access to the target service of the executor plugin (e.g. an HPC middleware like slurm with the sbatch command, or internet access to submit jobs to some cloud provider, e.g. azure).
The flag --default-resources ensures that Snakemake auto-calculates the mem and disk resources for each job, based on the input file size.
The values assumed there are conservative and should usually suffice.
However, you can always override those defaults by specifying the resources in your Snakemake rules or via the --set-resources flag.
Depending on the executor plugin, you might either rely on a shared local filesystem or use a remote filesystem or storage. For the latter, you have to additionally use a suitable storage plugin (see section storage plugins in the sidebar of this catalog) and eventually check for further recommendations in the sections below.
All arguments can also be persisted via a profile, such that they don’t have to be specified on each invocation. Here, this would mean the following entries inside of the profile
executor: aws-batch-flex
default_resources: []
For specifying other default resources than the built-in ones, see the docs.
Settings
The executor plugin has the following settings (which can be passed via command line, the workflow or environment variables, if provided in the respective columns):
Further details
Setup
Install the plugin together with the S3 storage plugin, which it uses for all files but doesn’t
depend on (in pixi, both go under [pypi-dependencies]):
pip install snakemake-executor-plugin-aws-batch-flex snakemake-storage-plugin-s3
Besides --executor aws-batch-flex, a run needs a queue and S3 storage, best kept in a profile
(see the example below): --aws-batch-flex-queue, --default-storage-provider s3 and
--default-storage-prefix s3://BUCKET/PREFIX.
You need a Batch queue whose instances have the Snakemake environment. In the repository,
bash scripts/setup.sh --region eu-west-1 builds the AMI (with Snakemake, conda and pandas),
creates the queue, compute environment, roles, log group and S3 bucket with Terraform, and
installs a global profile called smkflex, so snakemake --profile smkflex works in any
folder. The
README
walks through it step by step, from an empty AWS account to a finished test run.
To try the plugin on an existing queue without building an AMI, set
aws-batch-flex-bootstrap: auto: Snakemake is then installed into each container when its
job starts (about 10-15 s per job; needs internet access and curl, wget or pip in the
image).
Example profile
executor: aws-batch-flex
default-storage-provider: s3
default-storage-prefix: s3://my-bucket/snakemake
aws-batch-flex-queue: my-queue
aws-batch-flex-region: eu-west-1
aws-batch-flex-job-role-arn: arn:aws:iam::123456789012:role/snakemake-job
aws-batch-flex-bootstrap: host
aws-batch-flex-default-image: buildpack-deps:bookworm-scm
jobs: 100
Terraform’s snakemake_profile output prints one filled in for your account.
Rules
rule align:
input: "data/{sample}.fq"
output: "results/{sample}.sam"
container: "docker://quay.io/biocontainers/bwa:0.7.17--h7132678_9"
threads: 8
resources: mem_mb=16000, runtime=120, batch_queue="big-queue", batch_tags="stage=align"
shell: "bwa mem -t {threads} ref.fa {input} > {output}"
threadssets vCPUs,mem_mbmemory (plus 256 MiB for the Snakemake process in the job),runtime(minutes) the timeout, andgpuGPUs. When Snakemake retries a job that ran out of memory (--retries), the retry gets twice as much.disk_mbsets the job’s disk on Fargate (up to 200 GiB). On EC2, jobs share the instance’s disk anddisk_mbisn’t enforced.batch_shm_mbsets the size of/dev/shm(EC2 only);batch_spot_retriesandbatch_priorityset Spot retries and fair-share priority per rule.batch_job_definition(oraws-batch-flex-job-definitionfor all rules) uses an existing job definition instead of registering one.batch_queuesends a rule to another queue; EC2, Spot and Fargate queues can be mixed in one run.batch_tagsadds tags to that rule’s jobs; every job is also tagged with the run, workflow, rule and job ID.Python
script:rules run with the image’s own Python (3.10 or newer), so they can use its packages, unless their pandas/numpy/polarsparamsneed packages it lacks;batch_script_python="host"always uses Snakemake’s instead.conda:andwrapper:work with--sdm conda(conda from the image, or baked into the AMI). Built envs are reused rather than rebuilt in every job: by default, by the jobs on the same EC2 instance; withaws-batch-flex-conda-cacheset to an S3 URL, also from S3 by later jobs and runs.If
snakemakeis killed, the jobs it left running are cancelled when you restart it.Private images: ECR works through the IAM roles; other registries through Secrets Manager (
aws-batch-flex-registry-credentials).
At the end of a run the plugin prints what each rule used: vCPU- and GiB-hours, peak memory,
the most vCPUs busy at once and the most disk its jobs took, with set-resources: and
set-threads: blocks to paste into the project profile. Costs come from AWS Billing, by the
tags on every job (snakemake-run-id, snakemake-rule).
Published pipelines and long runs
Pipelines from the workflow catalog run unchanged: deploy them with snakedeploy, then run
smkflex init (gives the project its own prefix in the bucket) and smkflex push data
(uploads the inputs). smkflex run runs Snakemake itself as a Batch job, so nothing has to stay
running on your machine; smkflex logs, status and cancel follow and stop it.
Limits
Host mode needs glibc images with
/bin/shand bash (no Alpine).pipe()doesn’t work; Singularity/Apptainer images can’t be used.All rules in a group must use the same image.
The README covers setup, and the Reference lists every option, what has been tested on AWS, the remaining limits and the IAM permissions needed.