/
emr-terminate-cluster.ts
88 lines (77 loc) · 2.58 KB
/
emr-terminate-cluster.ts
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
import { Construct } from 'constructs';
import * as iam from '../../../aws-iam';
import * as sfn from '../../../aws-stepfunctions';
import { Stack } from '../../../core';
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
/**
* Properties for EmrTerminateCluster
*
*/
export interface EmrTerminateClusterProps extends sfn.TaskStateBaseProps {
/**
* The ClusterId to terminate.
*/
readonly clusterId: string;
}
/**
* A Step Functions Task to terminate an EMR Cluster.
*
*/
export class EmrTerminateCluster extends sfn.TaskStateBase {
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [
sfn.IntegrationPattern.REQUEST_RESPONSE,
sfn.IntegrationPattern.RUN_JOB,
];
protected readonly taskPolicies?: iam.PolicyStatement[];
protected readonly taskMetrics?: sfn.TaskMetricsConfig;
private readonly integrationPattern: sfn.IntegrationPattern;
constructor(scope: Construct, id: string, private readonly props: EmrTerminateClusterProps) {
super(scope, id, props);
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.RUN_JOB;
validatePatternSupported(this.integrationPattern, EmrTerminateCluster.SUPPORTED_INTEGRATION_PATTERNS);
this.taskPolicies = this.createPolicyStatements();
}
/**
* @internal
*/
protected _renderTask(): any {
return {
Resource: integrationResourceArn('elasticmapreduce', 'terminateCluster', this.integrationPattern),
Parameters: sfn.FieldUtils.renderObject({
ClusterId: this.props.clusterId,
}),
};
}
/**
* This generates the PolicyStatements required by the Task to call TerminateCluster.
*/
private createPolicyStatements(): iam.PolicyStatement[] {
const stack = Stack.of(this);
const policyStatements = [
new iam.PolicyStatement({
actions: [
'elasticmapreduce:DescribeCluster',
'elasticmapreduce:TerminateJobFlows',
],
resources: [
Stack.of(this).formatArn({
service: 'elasticmapreduce',
resource: 'cluster',
resourceName: '*',
}),
],
}),
];
if (this.integrationPattern === sfn.IntegrationPattern.RUN_JOB) {
policyStatements.push(new iam.PolicyStatement({
actions: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'],
resources: [stack.formatArn({
service: 'events',
resource: 'rule',
resourceName: 'StepFunctionsGetEventForEMRTerminateJobFlowsRule',
})],
}));
}
return policyStatements;
}
}