You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 9, 2023. It is now read-only.
Bug Fixes
* explicitly stop ecs before starting ebs autoscale on /var/lib/docker
* move nextflow additions to before start ecs
* add steps missing that are documented in https://docs.docker.com/storage/storagedriver/btrfs-driver/
Improvements
* Adding SSM agent and permissions to Batch hosts to allow SSM capabilities like Session Manager to facilitate troubleshooting via SSH without needing an EC2 keypair.
* refactor containers and job defs
* use host bind mounted awscli
* use job def environment variables for execution options
* use common entrypoint script for all containers
* update sfn example to use dynamic parallelism
* remove unneeded parameters from job definitions
* update example workflow input
* update build dependencies
* explicitly add pip
* unpin cfn-lint. we need this to stay up to date.
* use common build script for tooling containers
* add container build template
* refactor step functions stack into separate templates
* create a generic workflow template that uses nested templates to build individual containers and the state machine for the workflow
* simplify the workflow definition templates - the container builds and IAM role creation happens in parent templates
* add UpdateReplacePolicy for S3 Buckets
Documentation Updates
* update nextflow documentation
* fix a couple inconsistencies
* improve flow and clarity
* typo fixes
* update step functions docs
* update images
* add more details on job definition and sfn task
* add more details on the example workflow
* fix job output prefix in example input
* update workflow completion time
* add more detailed explanations of important job def parts and how they translate into sfn task code.
Copy file name to clipboardExpand all lines: docs/orchestration/nextflow/nextflow-overview.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@ Nextflow can be run either locally or on a dedicated EC2 instance. The latter i
8
8
9
9
## Full Stack Deployment
10
10
11
-
The following CloudFormation template will launch an EC2 instance pre-configured for using Nextflow.
11
+
_For the impatient:_
12
+
The following CloudFormation template will create all the resources you need to runs Nextflow using the architecture shown above. It combines the CloudFormation stacks referenced below in the [Requirements](#requirements) section.
12
13
13
14
| Name | Description | Source | Launch Stack |
14
15
| -- | -- | :--: | -- |
@@ -20,14 +21,24 @@ When the above stack is complete, you will have a preconfigured Batch Job Defini
20
21
21
22
To get started using Nextflow on AWS you'll need the following setup in your AWS account:
22
23
23
-
* The core set of resources (S3 Bucket, IAM Roles, AWS Batch) described in the [Getting Started](../../../core-env/introduction) section.
24
-
* A containerized `nextflow` executable that pulls configuration and workflow definitions from S3
24
+
* The core set of resources (S3 Bucket, IAM Roles, AWS Batch) described in the [Core Environment](../../../core-env/introduction) section.
25
+
26
+
If you are in a hurry, you can create the complete Core Environment using the following CloudFormation template:
27
+
28
+
| Name | Description | Source | Launch Stack |
29
+
| -- | -- | :--: | :--: |
30
+
{{ cfn_stack_row("GWFCore (Existing VPC)", "GWFCore-Full", "aws-genomics-root-novpc.template.yaml", "Create EC2 Launch Templates, AWS Batch Job Queues and Compute Environments, a secure Amazon S3 bucket, and IAM policies and roles within an **existing** VPC. _NOTE: You must provide VPC ID, and subnet IDs_.") }}
31
+
32
+
!!! note
33
+
The CloudFormation above does **not** create a new VPC, and instead will create associated resources in an existing VPC of your choosing, or your default VPC. To automate creating a new VPC to isolate your resources, you can use the [AWS VPC QuickStart](https://aws.amazon.com/quickstart/architecture/vpc/).
34
+
35
+
* A containerized `nextflow` executable with a custom entrypoint script that draws configuration information from AWS Batch supplied environment variables
25
36
* The AWS CLI installed in job instances using `conda`
26
37
* A Batch Job Definition that runs a Nextflow head node
27
-
* An IAM Role for the Nextflow head node job that allows it access to AWS Batch
28
-
* (optional) An S3 Bucket to store your Nextflow workflow definitions
38
+
* An IAM Role for the Nextflow head node job that allows it to submit AWS Batch jobs
39
+
* (optional) An S3 Bucket to store your Nextflow session cache
29
40
30
-
The last five items above are created by the following CloudFormation template:
41
+
The five items above are created by the following CloudFormation template:
The actual Launch Template used in the [Core Environment](../../core-env/introduction.md) does a couple more things, like installing additional resources for [managing space for the job](../../core-env/create-custom-compute-resources.md)
197
+
184
198
### Batch job definition
185
199
186
200
An AWS Batch Job Definition for the containerized Nextflow described above is shown below.
@@ -374,7 +388,7 @@ You can customize these job definitions to incorporate additional environment va
374
388
!!! important
375
389
Instances provisioned using the Nextflow specific EC2 Launch Template configure `/var/lib/docker` in the host instance to use automatically [expandable scratch space](../../../core-env/create-custom-compute-resources/), allowing containerized jobs to stage as much data as needed without running into disk space limits.
376
390
377
-
### Running the workflow
391
+
### Running workflows
378
392
379
393
To run a workflow you submit a `nextflow` Batch job to the appropriate Batch Job Queue via:
@@ -41,6 +41,7 @@ State machines that use AWS Batch for job execution and send events to CloudWatc
41
41
"Version": "2012-10-17",
42
42
"Statement": [
43
43
{
44
+
"Sid": "enable submitting batch jobs",
44
45
"Effect": "Allow",
45
46
"Action": [
46
47
"batch:SubmitJob",
@@ -64,9 +65,39 @@ State machines that use AWS Batch for job execution and send events to CloudWatc
64
65
}
65
66
```
66
67
68
+
For more complex workflows that use nested workflows or require more complex input parsing, you need to add additional permissions for executing Step Functions State Machines and invoking Lambda functions:
69
+
70
+
```json
71
+
{
72
+
"Version": "2012-10-17",
73
+
"Statement": [
74
+
{
75
+
"Sid": "enable calling lambda functions",
76
+
"Effect": "Allow",
77
+
"Action": [
78
+
"lambda:InvokeFunction"
79
+
],
80
+
"Resource": "*"
81
+
},
82
+
{
83
+
"Sid": "enable calling other step functions",
84
+
"Effect": "Allow",
85
+
"Action": [
86
+
"states:StartExecution"
87
+
],
88
+
"Resource": "*"
89
+
},
90
+
...
91
+
]
92
+
}
93
+
```
94
+
95
+
!!! note
96
+
All `Resource` values in the policy statements above can be scoped to be more specific if needed.
97
+
67
98
## Step Functions State Machine
68
99
69
-
Workflows in AWS Step Functions are built using [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html) (ASL), a declarative, JSON-based, structured language used to define your statemachine, a collection of states that can do work (Task states), determine which states to transition to next (Choice states), stop an execution with an error (Fail states), and so on.
100
+
Workflows in AWS Step Functions are built using [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html) (ASL), a declarative, JSON-based, structured language used to define a "state-machine". An AWS Step Functions State-Machine is a collection of states that can do work (Task states), determine which states to transition to next (Choice states), stop an execution with an error (Fail states), and so on.
It is recommended to have [Batch Job Definitions](https://docs.aws.amazon.com/batch/latest/userguide/job_definitions.html) created for your tooling prior to building a Step Functions state machine. These can then be referenced in state machine `Task` states by their respective ARNs.
127
-
128
-
Step Functions will use the Batch Job Definition to define compute resource requirements and parameter defaults for the Batch Job it submits.
157
+
[AWS Batch Job Definitions](https://docs.aws.amazon.com/batch/latest/userguide/job_definitions.html) are used to define compute resource requirements and parameter defaults for an AWS Batch Job. These are then referenced in state machine `Task` states by their respective ARNs.
129
158
130
159
An example Job Definition for the `bwa-mem` sequence aligner is shown below:
131
160
@@ -134,58 +163,85 @@ An example Job Definition for the `bwa-mem` sequence aligner is shown below:
The Job Definition above assumes that `bwa-mem` has been containerized with an
174
-
`entrypoint` script that handles Amazon S3 URIs for input and output data
175
-
staging.
222
+
There are three key parts of the above definition to take note of.
176
223
177
-
Because data staging requirements can be unique to the tooling used, neither AWS Batch nor Step Functions handles this automatically.
224
+
* Command and Parameters
225
+
226
+
The **command** is a list of strings that will be sent to the container. This is the same as the `...` arguments that you would provide to a `docker run mycontainer ...` command.
227
+
228
+
**Parameters** are placeholders that you define whose values are substituted when a job is submitted. In the case above a `threads` parameter is defined with a default value of `8`. The job definition's `command` references this parameter with `Ref::threads`.
229
+
230
+
!!! note
231
+
Parameter references in the command list must be separate strings - concatenation with other parameter references or static values is not allowed.
232
+
233
+
* Environment
234
+
235
+
**Environment** defines a set of environment variables that will be available for the container. For example, you can define environment variables used by the container entrypoint script to identify data it needs to stage in.
236
+
237
+
* Volumes and Mount Points
238
+
239
+
Together, **volumes** and **mountPoints** define what you would provide as using a `-v hostpath:containerpath` option to a `docker run` command. These can be used to map host directories with resources (e.g. data or tools) used by all containers. In the example above, a `scratch` volume is mapped so that the container can utilize a larger disk on the host. Also, a version of the AWS CLI installed with `conda` is mapped into the container - enabling the container to have access to it (e.g. so it can transfer data from S3 and back) with out explicitly building in.
178
240
179
-
!!! note
180
-
The `volumes` and `mountPoints` specifications allow the job container to
181
-
use scratch storage space on the instance it is placed on. This is equivalent
182
-
to the `-v host_path:container_path` option provided to a `docker run` call
183
-
at the command line.
184
241
185
242
### State Machine Batch Job Tasks
186
243
187
-
Conveniently for genomics workflows, AWS Step Functions has built-in integration with AWS Batch (and [several other services](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-connectors.html)), and provides snippets of code to make developing your state-machine
188
-
Batch tasks easier.
244
+
AWS Step Functions has built-in integration with AWS Batch (and [several other services](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-connectors.html)), and provides snippets of code to make developing your state-machine tasks easier.
189
245
190
246

191
247
@@ -202,7 +258,15 @@ would look like the following:
When the Task state completes Step Functions will add information to a new `status` key under `bwa-mem` in the JSON object. The complete object will be passed on to the next state in the workflow.
228
294
229
295
## Example state machine
230
296
231
-
All of the above is created by the following CloudFormation template.
297
+
The following CloudFormation template creates container images, AWS Batch Job Definitions, and an AWS Step Functions State Machine for a simple genomics workflow using bwa, samtools, and bcftools.
232
298
233
299
| Name | Description | Source | Launch Stack |
234
300
| -- | -- | :--: | :--: |
235
-
{{ cfn_stack_row("AWS Step Functions Example", "SfnExample", "step-functions/sfn-example.template.yaml", "Create a Step Functions State Machine, Batch Job Definitions, and container images to run an example genomics workflow") }}
301
+
{{ cfn_stack_row("AWS Step Functions Example", "SfnExample", "step-functions/sfn-workflow.template.yaml", "Create a Step Functions State Machine, Batch Job Definitions, and container images to run an example genomics workflow") }}
236
302
237
303
!!! note
238
304
The stack above needs to create several IAM Roles. You must have administrative privileges in your AWS Account for this to succeed.
239
305
306
+
The example workflow is a simple secondary analysis pipeline that converts raw FASTQ files into VCFs with variants called for a list of chromosomes. It uses the following open source based tools:
307
+
308
+
* `bwa-mem`: Burrows-Wheeler Aligner for aligning short sequence reads to a reference genome
309
+
* `samtools`: **S**equence **A**lignment **M**apping library for indexing and sorting aligned reads
310
+
* `bcftools`: **B**inary (V)ariant **C**all **F**ormat library for determining variants in sample reads relative to a reference genome
311
+
312
+
Read alignment, sorting, and indexing occur sequentially by Step Functions Task States. Variant calls for chromosomes occur in parallel using a Step Functions Map State and sub-Task States therein. All tasks submit AWS Batch Jobs to perform computational work using containerized versions of the tools listed above.
313
+
314
+

315
+
316
+
The tooling containers used by the workflow use a [generic entrypoint script]({{ repo_url + "tree/master/src/containers" }}) that wraps the underlying tool and handles S3 data staging. It uses the AWS CLI to transfer objects and environment variables to identify data inputs and outputs to stage.
317
+
240
318
### Running the workflow
241
319
242
320
When the stack above completes, go to the outputs tab and copy the JSON string provided in `StateMachineInput`.
The input JSON will like the following, but with the values for `queue` and `JOB_OUTPUT_PREFIX` prepopulated with resource names specific to the stack created by the CloudFormation template above:
326
+
327
+
```json
328
+
{
329
+
"params": {
330
+
"__comment__": {
331
+
"replace values for `queue` and `environment.JOB_OUTPUT_PREFIX` with values that match your resources": {
332
+
"queue": "Name or ARN of the AWS Batch Job Queue the workflow will use by default.",
333
+
"environment.JOB_OUTPUT_PREFIX": "S3 URI (e.g. s3://bucket/prefix) you are using for workflow inputs and outputs."
0 commit comments