/
emrcfn.yaml
453 lines (398 loc) · 16.6 KB
/
emrcfn.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
AWSTemplateFormatVersion: 2010-09-09
Description: "Create an EMR cluster with optionally spot task instances"
Parameters:
## Need these to instantiate the template
VpcId:
Type: AWS::EC2::VPC::Id
Subnet:
Type: AWS::EC2::Subnet::Id
KeyPair:
Type: AWS::EC2::KeyPair::KeyName
S3ConfigPrefix:
Type: String
## Instance types
MasterInstanceType:
Type: String
Default: m5.xlarge
CoreInstanceType:
Type: String
Default: m5.xlarge
TaskInstanceType:
Type: String
Default: m5.xlarge
## Instance counts and bounds
InitialCoreSize:
Type: Number
Default: 2
MaxCoreSize:
Type: Number
Default: 10
InitialTaskSize:
Type: Number
Default: 0
MaxTaskSize:
Type: Number
Default: 10
## Software versions
ReleaseLabel:
Type: String
Default: emr-5.27.0
MinicondaScriptURL:
Type: String
Default: "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
## Misc parameters
CoreStorage:
Type: Number
Default: 200
TaskStorage:
Type: Number
Default: 200
RootVolumeSize:
Type: Number
Default: 32
SpotPrice:
Type: Number
Default: 0.1 # set to 0 for on-demand
ReplicationFactor:
Type: Number
Default: -1
SparkDriverMemory:
Type: String
Default: 1g
SparkExecutorMemory:
Type: String
Default: 1g
SparkMaxResultSize:
Type: String
Default: 1g
Conditions:
WithSpotPrice:
!Not [!Equals [0, !Ref SpotPrice]]
DefaultReplication:
!Equals [-1, !Ref ReplicationFactor]
Resources:
LogBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
AccessControl: Private
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Allow SSH from anywhere"
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
ServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- elasticmapreduce.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole
JobFlowRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- ec2.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role
AutoscalingRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- elasticmapreduce.amazonaws.com
- application-autoscaling.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref JobFlowRole
Cluster:
Type: AWS::EMR::Cluster
Properties:
Name: !Ref "AWS::StackName"
ReleaseLabel: !Ref ReleaseLabel
VisibleToAllUsers: true
BootstrapActions:
- Name: InstallSystemSoftware
ScriptBootstrapAction:
Path: !Sub s3://${S3ConfigPrefix}/config/bootstrap/install_system_software/run.sh
# Spark dependency management is awful, so we're going to
# install miniconda on the worker nodes to get known package
# versions etc. A step run after Spark installation tells it
# to use the miniconda python.
- Name: InstallMiniconda
ScriptBootstrapAction:
Path: !Sub s3://${S3ConfigPrefix}/config/bootstrap/install_miniconda/run.sh
Args:
- !Ref S3ConfigPrefix
- !Ref MinicondaScriptURL
LogUri: !Sub
- "s3://${bucket}/emr-logs/"
- { bucket: !Ref LogBucket }
Applications:
- Name: Hadoop
- Name: Spark
- Name: Tez
- Name: Livy
- Name: Pig
- Name: Mahout
- Name: Hue
- Name: Ganglia
- Name: Presto
- Name: Hive
- Name: JupyterHub
AutoScalingRole: !Ref AutoscalingRole
JobFlowRole: !Ref InstanceProfile
ServiceRole: !Ref ServiceRole
ScaleDownBehavior: TERMINATE_AT_TASK_COMPLETION
EbsRootVolumeSize: !Ref RootVolumeSize
Configurations:
- Classification: spark
ConfigurationProperties:
maximizeResourceAllocation: true
- Classification: spark-defaults
ConfigurationProperties:
spark.sql.parquet.enableVectorizedReader: false
spark.sql.files.ignoreCorruptFiles: true
spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version: 2
spark.task.maxFailures: 20
spark.driver.memory: !Ref SparkDriverMemory
spark.executor.memory: !Ref SparkExecutorMemory
spark.driver.maxResultSize: !Ref SparkMaxResultSize
- Classification: hdfs-site
ConfigurationProperties:
dfs.replication: !If [DefaultReplication, !Ref "AWS::NoValue", !Ref ReplicationFactor]
- Classification: presto-connector-hive
ConfigurationProperties:
hive.metastore.glue.datacatalog.enabled: true
- Classification: hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Classification: spark-hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Classification: yarn-site
ConfigurationProperties:
yarn.log-aggregation-enable: true
yarn.log-aggregation.retain-seconds: -1
yarn.nodemanager.remote-app-log-dir: !Sub
- "s3://${bucket}/aggregated-logs/"
- { bucket: !Ref LogBucket }
Instances:
TerminationProtected: false
Ec2KeyName: !Ref KeyPair
Ec2SubnetId: !Ref Subnet
AdditionalMasterSecurityGroups:
- !Ref SecurityGroup
MasterInstanceGroup:
InstanceCount: 1
InstanceType: !Ref MasterInstanceType
Market: ON_DEMAND
Name: MasterInstance
CoreInstanceGroup:
InstanceCount: !Ref InitialCoreSize
InstanceType: !Ref CoreInstanceType
Market: ON_DEMAND
Name: CoreInstance
EbsConfiguration:
EbsBlockDeviceConfigs:
- VolumeSpecification:
SizeInGB: !Ref CoreStorage
VolumeType: gp2
VolumesPerInstance: 1
EbsOptimized: true
AutoScalingPolicy:
Constraints:
MinCapacity: 1
MaxCapacity: !Ref MaxCoreSize
Rules:
- Name: CoreNodeScaleOut
Description: "Core node scale-out based on HDFS utilization"
Action:
SimpleScalingPolicyConfiguration:
AdjustmentType: CHANGE_IN_CAPACITY
ScalingAdjustment: 1
CoolDown: 300
Trigger:
CloudWatchAlarmDefinition:
ComparisonOperator: GREATER_THAN
EvaluationPeriods: 1
MetricName: HDFSUtilization
Namespace: AWS/ElasticMapReduce
Period: 300
Threshold: 80
Statistic: AVERAGE
Unit: PERCENT
Dimensions:
- Key: JobFlowId
Value: "${emr.clusterId}"
TaskInstanceGroupConfig:
Type: AWS::EMR::InstanceGroupConfig
Properties:
Name: TaskInstance
InstanceRole: TASK
JobFlowId: !Ref Cluster
InstanceCount: !Ref InitialTaskSize
InstanceType: !Ref TaskInstanceType
Market: !If [WithSpotPrice, SPOT, ON_DEMAND]
BidPrice: !If [WithSpotPrice, !Ref SpotPrice, !Ref "AWS::NoValue"]
EbsConfiguration:
EbsBlockDeviceConfigs:
- VolumeSpecification:
SizeInGB: !Ref TaskStorage
VolumeType: gp2
VolumesPerInstance: 1
EbsOptimized: true
Configurations:
- Classification: spark
ConfigurationProperties:
maximizeResourceAllocation: true
- Classification: spark-defaults
ConfigurationProperties:
spark.sql.parquet.enableVectorizedReader: false
spark.sql.files.ignoreCorruptFiles: true
spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version: 2
spark.task.maxFailures: 20
spark.driver.memory: !Ref SparkDriverMemory
spark.executor.memory: !Ref SparkExecutorMemory
spark.driver.maxResultSize: !Ref SparkMaxResultSize
- Classification: hdfs-site
ConfigurationProperties:
dfs.replication: !If [DefaultReplication, !Ref "AWS::NoValue", !Ref ReplicationFactor]
- Classification: presto-connector-hive
ConfigurationProperties:
hive.metastore.glue.datacatalog.enabled: true
- Classification: hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Classification: spark-hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
- Classification: yarn-site
ConfigurationProperties:
yarn.log-aggregation-enable: true
yarn.log-aggregation.retain-seconds: -1
yarn.nodemanager.remote-app-log-dir: !Sub
- "s3://${bucket}/aggregated-logs/"
- { bucket: !Ref LogBucket }
AutoScalingPolicy:
Constraints:
MinCapacity: 0
MaxCapacity: !Ref MaxTaskSize
Rules:
- Name: TaskNodeScaleOut
Description: "Task node scale-out based on memory utilization"
Action:
SimpleScalingPolicyConfiguration:
AdjustmentType: CHANGE_IN_CAPACITY
ScalingAdjustment: 1
CoolDown: 300
Trigger:
CloudWatchAlarmDefinition:
ComparisonOperator: LESS_THAN
EvaluationPeriods: 1
MetricName: YARNMemoryAvailablePercentage
Namespace: AWS/ElasticMapReduce
Period: 300
Threshold: 20
Statistic: AVERAGE
Unit: PERCENT
Dimensions:
- Key: JobFlowId
Value: "${emr.clusterId}"
- Name: TaskNodeScaleIn
Description: "Task node scale-in based on memory utilization"
Action:
SimpleScalingPolicyConfiguration:
AdjustmentType: CHANGE_IN_CAPACITY
ScalingAdjustment: -1
CoolDown: 300
Trigger:
CloudWatchAlarmDefinition:
ComparisonOperator: GREATER_THAN
EvaluationPeriods: 1
MetricName: YARNMemoryAvailablePercentage
Namespace: AWS/ElasticMapReduce
Period: 300
Threshold: 75
Statistic: AVERAGE
Unit: PERCENT
Dimensions:
- Key: JobFlowId
Value: "${emr.clusterId}"
DebugSetupStep:
Type: AWS::EMR::Step
Properties:
Name: SetupDebuggingTool
ActionOnFailure: CONTINUE
JobFlowId: !Ref Cluster
HadoopJarStep:
Jar: "command-runner.jar"
Args:
- state-pusher-script
InstallSpatialStep:
Type: AWS::EMR::Step
Properties:
Name: InstallSpatial
ActionOnFailure: CONTINUE
JobFlowId: !Ref Cluster
HadoopJarStep:
Jar: !Sub s3://${AWS::Region}.elasticmapreduce/libs/script-runner/script-runner.jar
Args:
- !Sub s3://${S3ConfigPrefix}/config/step/install_spatial/run.sh
- !Ref S3ConfigPrefix
# Tell Spark to use miniconda rather than the system python
SetupMinicondaStep:
Type: AWS::EMR::Step
Properties:
Name: SetupMiniconda
ActionOnFailure: CONTINUE
JobFlowId: !Ref Cluster
HadoopJarStep:
Jar: !Sub s3://${AWS::Region}.elasticmapreduce/libs/script-runner/script-runner.jar
Args:
- !Sub s3://${S3ConfigPrefix}/config/step/setup_miniconda/run.sh
- !Ref S3ConfigPrefix
# Get EMR's Docker Jupyterhub configured to use the same conda environment
# we've deployed to the nodes and made Spark's default. This way, no
# confusing version mismatch errors.
SetupJupyterhubStep:
Type: AWS::EMR::Step
Properties:
Name: SetupJupyterhub
ActionOnFailure: CONTINUE
JobFlowId: !Ref Cluster
HadoopJarStep:
Jar: !Sub s3://${AWS::Region}.elasticmapreduce/libs/script-runner/script-runner.jar
Args:
- !Sub s3://${S3ConfigPrefix}/config/step/setup_jupyterhub/run.sh
- !Ref S3ConfigPrefix
Outputs:
ClusterDNS:
Description: EMR Cluster DNS
Value: !GetAtt Cluster.MasterPublicDNS
ClusterID:
Description: EMR Cluster ID
Value: !Ref Cluster