/
dask-fargate-nested.yaml
202 lines (180 loc) · 6.4 KB
/
dask-fargate-nested.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# This template provides a quick start distributed environment for dask on AWS.
# It will:
# 1) Create a pipeline to build a container image for dask and other necessary software
# 2) Create a new dask environment with VPC, ECS cluster and SageMaker notebook
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: GitHub source details for dask container build artefacts
Parameters:
- DaskWorkerGitHubOrg
- DaskWorkerGitSourceBranch
- DaskWorkerGitSourceRepo
- DaskWorkerGitToken
- Label:
default: SageMaker notebook settings
Parameters:
- SagemakerCodeRepo
- SagemakerNotebookInstance
- Label:
default: Dask worker task settings
Parameters:
- UseSpotPricing
- DaskWorkerCPU
- DaskWorkerMemory
- Label:
default: Build settings
Parameters:
- CodeBuildDockerImage
- UseLocalTemplates
- EnvironmentTemplateLocation
- PipelineTemplateLocation
Parameters:
DaskWorkerGitToken:
Type: String
Description: GitHub OAuth Token for accessing the Dask worker repository
MinLength: 40
AllowedPattern: "[a-zA-Z0-9_]+"
NoEcho: true
SagemakerCodeRepo:
Type: String
Description: Github Repository for loading into the Sagemaker Jupyter environment
Default: https://github.com/awslabs/amazon-asdi.git
SagemakerNotebookInstance:
Type: String
Description: SageMaker Notebook instance type
AllowedValues:
- ml.t3.medium
- ml.t3.large
- ml.t3.xlarge
- ml.t3.2xlarge
- ml.m5.large
- ml.m5.2xlarge
- ml.m5.4xlarge
Default: ml.m5.2xlarge
DaskWorkerGitSourceRepo:
Type: String
Description: GitHub Repository for building the container image for the Dask workers
Default: amazon-asdi
DaskWorkerGitHubOrg:
Type: String
Description: GitHub organization for Dask Worker repository
Default: awslabs
DaskWorkerGitSourceBranch:
Type: String
Description: GitHub Repository Branch for Dask workers
Default: main
CodeBuildDockerImage:
Type: String
Default: aws/codebuild/standard:5.0
EnvironmentTemplateLocation:
Type: String
Default: https://s3.amazonaws.com/docs.opendata.aws/cloudformation/dask-environment.yaml
Description: Location of the Dask environment CloudFormation template
PipelineTemplateLocation:
Type: String
Default: https://s3.amazonaws.com/docs.opendata.aws/cloudformation/dask-pipeline.yaml
Description: Location of the Dask pipeline CloudFormation template
UseLocalTemplates:
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'NO'
Description: Use local template files instead of S3 URLs (when using aws cloudformation package / deploy)?
UseSpotPricing:
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'NO'
Description: Use Fargate spot pricing for dask workers to reduce cost?
DaskWorkerCPU:
Type: String
AllowedValues:
- '1'
- '2'
- '4'
Default: '1'
Description: Number of vCPUs to allocate to each dask worker task
DaskWorkerMemory:
Type: String
AllowedValues:
- '2048'
- '4096'
- '8192'
- '16384'
Default: '8192'
Description: Amount of memory in MiB to allocate to each dask worker task
Mappings:
FargateCPUMap:
'1':
Value: '1024'
'2':
Value: '2048'
'4':
Value: '4096'
Conditions:
LocalTemplates: !Equals [!Ref UseLocalTemplates, 'YES']
S3Templates: !Not [!Condition LocalTemplates]
Resources:
# These resources are used by default, when the stack is launched through the console
# (eg via a link from github). The dask-pipeline and dask-environment templates must
# be stored in an S3 bucket, as specified in the location parameters.
DaskPipelineStack:
Type: AWS::CloudFormation::Stack
Condition: S3Templates
Properties:
TemplateURL: !Ref PipelineTemplateLocation
Parameters:
DaskWorkerGitToken: !Ref DaskWorkerGitToken
DaskWorkerGitSourceRepo: !Ref DaskWorkerGitSourceRepo
DaskWorkerGitHubOrg: !Ref DaskWorkerGitHubOrg
DaskWorkerGitSourceBranch: !Ref DaskWorkerGitSourceBranch
CodeBuildDockerImage: !Ref CodeBuildDockerImage
DaskEnvironmentStack:
Type: AWS::CloudFormation::Stack
Condition: S3Templates
DependsOn: DaskPipelineStack
Properties:
TemplateURL: !Ref EnvironmentTemplateLocation
Parameters:
SagemakerCodeRepo: !Ref SagemakerCodeRepo
DaskImage: !Sub '${DaskPipelineStack.Outputs.ECRRepositoryName}:latest'
DaskWorkerSpotPricing: !Ref UseSpotPricing
DaskWorkerCPU: !FindInMap [FargateCPUMap, !Ref DaskWorkerCPU, 'Value']
DaskWorkerMemory: !Ref DaskWorkerMemory
# Below are used when deploying from a local copy of the templates, via the AWS CLI
# with 'aws cloudformation package' and 'aws cloudformation deploy'
DaskPipelineStackFromLocal:
Type: AWS::CloudFormation::Stack
Condition: LocalTemplates
Properties:
TemplateURL: dask-pipeline.yaml
Parameters:
DaskWorkerGitToken: !Ref DaskWorkerGitToken
DaskWorkerGitSourceRepo: !Ref DaskWorkerGitSourceRepo
DaskWorkerGitHubOrg: !Ref DaskWorkerGitHubOrg
DaskWorkerGitSourceBranch: !Ref DaskWorkerGitSourceBranch
CodeBuildDockerImage: !Ref CodeBuildDockerImage
DaskEnvironmentStackFromLocal:
Type: AWS::CloudFormation::Stack
Condition: LocalTemplates
DependsOn: DaskPipelineStackFromLocal
Properties:
TemplateURL: dask-environment.yaml
Parameters:
SagemakerCodeRepo: !Ref SagemakerCodeRepo
DaskImage: !Sub '${DaskPipelineStackFromLocal.Outputs.ECRRepositoryName}:latest'
DaskWorkerSpotPricing: !Ref UseSpotPricing
DaskWorkerCPU: !FindInMap [FargateCPUMap, !Ref DaskWorkerCPU, 'Value']
DaskWorkerMemory: !Ref DaskWorkerMemory
Outputs:
JupyterNotebook:
Description: URL of the Sagemaker Notebook instance
Value:
Fn::If:
- LocalTemplates
- !GetAtt DaskEnvironmentStackFromLocal.Outputs.JupyterNotebook
- !GetAtt DaskEnvironmentStack.Outputs.JupyterNotebook