Skip to content

Commit 3047afb

Browse files
Nextflow launch form - Add a new parameter named "InputDataPattern" field.
1) Validate the outdatalocation param which consists of s3 else localpath accordingly prefix the s3:// in the OutputDataLocation 2) Nextflow launch form - Add a new parameter named "InputDataPattern" field. 3) Help text has changed for InputDataLocation and InputDataPattern
1 parent eb4f72d commit 3047afb

1 file changed

Lines changed: 79 additions & 23 deletions

File tree

cft-templates/nextflow-advanced.yaml

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2+
23
Description: 'AWS CloudFormation Sample Template Sample template EIP_With_Association:
34
This template shows how to associate an Elastic IP address with an Amazon EC2 instance
45
- you can use this same technique to associate an EC2 instance with an Elastic IP
56
Address that is not created inside the template by replacing the EIP reference in
67
the AWS::EC2::EIPAssoication resource type with the IP address of the external EIP.
78
**WARNING** This template creates an Amazon EC2 instance and an Elastic IP Address.
89
You will be billed for the AWS resources used if you create a stack from this template.'
10+
911
Metadata:
1012
AWS::CloudFormation::Interface:
1113
ParameterGroups:
@@ -14,7 +16,8 @@ Metadata:
1416
Parameters:
1517
- PipelineName
1618
- PipelineContainer
17-
- InputDataLocation
19+
- InputDataLocation
20+
- InputDataPattern
1821
- OutputDataLocation
1922
- Label:
2023
default: Head Node Configuration
@@ -37,6 +40,7 @@ Metadata:
3740
- ProjectId
3841
ALB: true
3942
ProductName: nextflow
43+
4044
Parameters:
4145
VpcId:
4246
Type: AWS::EC2::VPC::Id
@@ -50,18 +54,22 @@ Parameters:
5054
Default: 16
5155
PipelineContainer:
5256
Type: String
53-
Default: nextflow/rnaseq-nf:latest
5457
Description: Public Docker container image of the pipeline to be executed. If you are using a custom pipeline, ensure that the custom container image is publicly available on Docker Hub
5558
InputDataLocation:
5659
Description: >-
5760
An S3 bucket which holds input data for the Nextflow pipeline. The bucket name must respect the S3 bucket naming conventions
5861
(can contain lowercase letters, numbers, periods and hyphens).
59-
Type: String
62+
Type: String
63+
InputDataPattern:
64+
Description: >-
65+
The pattern to match samples to be processed as inputs to the pipeline. E.g. data/ggal/*_{1,2}.fq. It can also point to a csv or tsv file that contains details of the files to be processed.
66+
Type: String
67+
Default: samplesheet.csv
6068
OutputDataLocation:
6169
Description: >-
6270
The full path on the local disk where outputs of the pipeline should be stored. The default path above will enable you to view the outputs via the browser. The path should be accessible to the user ec2-user.
6371
Alternately, provide an S3 bucket for storing analysis results. The bucket name must respect the S3 bucket naming conventions
64-
(can contain lowercase letters, numbers, periods and hyphens). Eg: s3://<BucketName>
72+
(can contain lowercase letters, numbers, periods and hyphens).
6573
Default: /home/ec2-user/nextflow/outputs/
6674
Type: String
6775
ComputeEnvMinvCpus:
@@ -111,16 +119,35 @@ Parameters:
111119
Type: String
112120
ProjectId:
113121
Type: String
122+
Namespace:
123+
Type: String
124+
Description: An environment name that will be prefixed to resource names
125+
S3Mounts:
126+
Type: String
127+
Description: A JSON array of objects with name, bucket, and prefix properties used to mount data
128+
IamPolicyDocument:
129+
Type: String
130+
Description: The IAM policy to be associated with the launched workstation
131+
EnvironmentInstanceFiles:
132+
Type: String
133+
Description: >-
134+
An S3 URI (starting with "s3://") that specifies the location of files to be copied to
135+
the environment instance, including any bootstrap scripts
136+
137+
Conditions:
138+
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
114139

115140
Resources:
116141
IamInstanceProfile:
117142
Type: AWS::IAM::InstanceProfile
118143
Properties:
119144
Roles:
120145
- Ref: EcsInstanceRole
146+
121147
EcsInstanceRole:
122148
Type: AWS::IAM::Role
123149
Properties:
150+
RoleName: !Join ['-', [Ref: Namespace, 'nextflow-head-role']]
124151
AssumeRolePolicyDocument:
125152
Version: '2008-10-17'
126153
Statement:
@@ -129,6 +156,12 @@ Resources:
129156
Principal:
130157
Service: ec2.amazonaws.com
131158
Action: sts:AssumeRole
159+
Policies:
160+
- !If
161+
- IamPolicyEmpty
162+
- !Ref 'AWS::NoValue'
163+
- PolicyName: !Join ['-', [Ref: Namespace, 's3-studydata-policy']]
164+
PolicyDocument: !Ref IamPolicyDocument
132165
ManagedPolicyArns:
133166
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
134167
- arn:aws:iam::aws:policy/AmazonS3FullAccess
@@ -137,6 +170,7 @@ Resources:
137170
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser
138171
- arn:aws:iam::aws:policy/AmazonElasticContainerRegistryPublicPowerUser
139172
- arn:aws:iam::aws:policy/AmazonSSMFullAccess
173+
140174
EC2LaunchTemplate:
141175
Type: AWS::EC2::LaunchTemplate
142176
Properties:
@@ -218,6 +252,7 @@ Resources:
218252
GroupDescription: SG for nextflow workflows on Batch
219253
VpcId:
220254
Ref: VpcId
255+
221256
S3Bucket:
222257
Type: AWS::S3::Bucket
223258
DeletionPolicy: Delete
@@ -339,6 +374,7 @@ Resources:
339374
- "ecs-tasks.amazonaws.com"
340375
Action:
341376
- "sts:AssumeRole"
377+
342378
BatchInstanceRole:
343379
Type: AWS::IAM::Role
344380
Properties:
@@ -410,11 +446,13 @@ Resources:
410446
- "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
411447
- "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
412448
- "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
449+
413450
BatchInstanceProfile:
414451
Type: AWS::IAM::InstanceProfile
415452
Properties:
416453
Roles:
417454
- Ref: BatchInstanceRole
455+
418456
BatchSpotFleetRole:
419457
Type: AWS::IAM::Role
420458
Properties:
@@ -429,6 +467,7 @@ Resources:
429467
- "sts:AssumeRole"
430468
ManagedPolicyArns:
431469
- "arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetTaggingRole"
470+
432471
BatchServiceRole:
433472
Type: AWS::IAM::Role
434473
Properties:
@@ -494,28 +533,45 @@ Resources:
494533
- Order: 1
495534
ComputeEnvironment: !Ref SpotComputeEnv
496535

497-
498536
EC2Instance:
499537
Type: AWS::EC2::Instance
538+
CreationPolicy:
539+
ResourceSignal:
540+
Timeout: PT10M
500541
Properties:
501542
UserData:
502543
Fn::Base64: !Sub |
503544
#!/bin/bash -xe
504545

546+
sudo yum update -y --security
505547
cd /root/
548+
549+
getOutputData=${OutputDataLocation}
550+
getFirstChar=`echo $getOutputData | cut -c1-1`
551+
552+
if [ "$getFirstChar" == "/" ]
553+
then :
554+
echo "Ngnix URL"
555+
OutputDataLocation=${OutputDataLocation}
556+
echo $OutputDataLocation
557+
else
558+
echo "S3 Path"
559+
OutputDataLocation="s3://"${OutputDataLocation}
560+
echo $OutputDataLocation
561+
fi
506562

507563
cd .nextflow/
508564
PROJECT_NF_CONFIG=config
509565

510566
cat << EOF >> $PROJECT_NF_CONFIG
511567
process.container = '${PipelineContainer}'
512-
docker.runOptions='-u 0:0'
513568
plugins {
514569
id 'nf-amazon'
515570
}
516571
docker.enabled = true
517-
params.outdir='${OutputDataLocation}'
518-
params.reads='s3://${InputDataLocation}'
572+
params.outdir='$OutputDataLocation'
573+
params.reads='s3://${InputDataLocation}/${InputDataPattern}'
574+
params.input='s3://${InputDataLocation}/${InputDataPattern}'
519575
profiles {
520576
standard {
521577
process.container = '${PipelineContainer}'
@@ -540,17 +596,23 @@ Resources:
540596

541597
NEXTFLOW_CONFIG=nextflow.config
542598

543-
NEXTFLOW_OUTPUT_PARAMS='\nparams.outdir="${OutputDataLocation}"'
544-
545-
echo -e $NEXTFLOW_OUTPUT_PARAMS >>$NEXTFLOW_CONFIG
546-
599+
cat << EOF >> $NEXTFLOW_CONFIG
600+
params.outdir='$OutputDataLocation'
601+
EOF
602+
547603
docker pull ${PipelineContainer}
548604
chown -R ec2-user:ec2-user /home/ec2-user/
549605
chown -R ec2-user:ec2-user /home/ec2-user/.[^.]*
550606

551607
usermod -aG docker ec2-user
552-
gpasswd -a $USER docker
608+
gpasswd -a ec2-user docker
553609
systemctl restart docker
610+
611+
#Download and execute bootstrap script
612+
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
613+
chmod 500 "/tmp/get_bootstrap.sh"
614+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}'
615+
/opt/aws/bin/cfn-signal --exit-code 0 --resource EC2Instance --region ${AWS::Region} --stack ${AWS::StackName}
554616

555617
InstanceType: !Ref 'InstanceType'
556618
SecurityGroupIds:
@@ -565,11 +627,12 @@ Resources:
565627
Encrypted: true
566628
Tags:
567629
- Key: Name
568-
Value: !Join ['-', ['nextflow-head-node', !Ref "AWS::StackName"]]
630+
Value: !Join ['-', [Ref: Namespace, 'nextflow-head-node']]
569631
- Key: cost_resource
570632
Value: !Ref "AWS::StackName"
571633
- Key: Description
572634
Value: EC2 workspace instance
635+
573636
InstanceSecurityGroup:
574637
Type: AWS::EC2::SecurityGroup
575638
Properties:
@@ -592,20 +655,14 @@ Resources:
592655
FromPort: 443
593656
ToPort: 443
594657
CidrIp: !Ref 'AllowedSSHLocation'
595-
IPAddress:
596-
Type: AWS::EC2::EIP
597-
IPAssoc:
598-
Type: AWS::EC2::EIPAssociation
599-
Properties:
600-
InstanceId: !Ref 'EC2Instance'
601-
EIP: !Ref 'IPAddress'
658+
602659
Outputs:
603660
InstanceId:
604661
Description: InstanceId of the newly created EC2 instance
605662
Value: !Ref 'EC2Instance'
606663
InstanceIPAddress:
607664
Description: IP address of the newly created EC2 instance
608-
Value: !Ref 'IPAddress'
665+
Value: !GetAtt [EC2Instance, PublicIp]
609666
InstanceDNSName:
610667
Description: DNS name of the newly created EC2 instance
611668
Value: !GetAtt [EC2Instance, PublicDnsName]
@@ -627,4 +684,3 @@ Outputs:
627684
Value: !Ref EC2LaunchTemplate
628685
WorkDataLocation:
629686
Value: !Sub ${S3Bucket}
630-

0 commit comments

Comments
 (0)