Skip to content

Commit 55f08c9

Browse files
committed
add iam:CreateServiceLinkedRole permission
1 parent cf0daa3 commit 55f08c9

File tree

8 files changed

+168
-15
lines changed

8 files changed

+168
-15
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/emr-create-cluster-ebs.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/emr-create-cluster-ebs.template.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,31 @@
584584
}
585585
]
586586
},
587+
{
588+
"Action": "iam:CreateServiceLinkedRole",
589+
"Condition": {
590+
"StringEquals": {
591+
"iam:AWSServiceName": [
592+
"elasticmapreduce.amazonaws.com",
593+
"elasticmapreduce.amazonaws.com.cn"
594+
]
595+
}
596+
},
597+
"Effect": "Allow",
598+
"Resource": {
599+
"Fn::Join": [
600+
"",
601+
[
602+
"arn:",
603+
{
604+
"Ref": "AWS::Partition"
605+
},
606+
":iam::*:role/aws-service-role/elasticmapreduce.amazonaws.com*/AWSServiceRoleForEMRCleanup*"
607+
]
608+
]
609+
},
610+
"Sid": "ElasticMapReduceServiceLinkedRole"
611+
},
587612
{
588613
"Action": [
589614
"events:DescribeRule",

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/emrcreateclusterebsintegDefaultTestDeployAssert7DC4C06C.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/emrcreateclusterebsintegDefaultTestDeployAssert7DC4C06C.template.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/manifest.json

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/emr/integ.emr-create-cluster-with-ebs.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import * as iam from '../../../aws-iam';
1313
import * as sfn from '../../../aws-stepfunctions';
1414
import * as cdk from '../../../core';
15-
import { ValidationError } from '../../../core';
15+
import { Aws, ValidationError } from '../../../core';
1616
import { ENABLE_EMR_SERVICE_POLICY_V2 } from '../../../cx-api';
1717
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
1818

@@ -395,6 +395,24 @@ export class EmrCreateCluster extends sfn.TaskStateBase {
395395
resources: [serviceRole.roleArn, clusterRole.roleArn],
396396
}),
397397
);
398+
399+
// https://docs.aws.amazon.com/emr/latest/ManagementGuide/using-service-linked-roles-cleanup.html#create-service-linked-role
400+
policyStatements.push(
401+
new iam.PolicyStatement({
402+
sid: 'ElasticMapReduceServiceLinkedRole',
403+
actions: ['iam:CreateServiceLinkedRole'],
404+
resources: [`arn:${Aws.PARTITION}:iam::*:role/aws-service-role/elasticmapreduce.amazonaws.com*/AWSServiceRoleForEMRCleanup*`],
405+
conditions: {
406+
StringEquals: {
407+
'iam:AWSServiceName': [
408+
'elasticmapreduce.amazonaws.com',
409+
'elasticmapreduce.amazonaws.com.cn',
410+
],
411+
},
412+
},
413+
}),
414+
);
415+
398416
if (autoScalingRole !== undefined) {
399417
policyStatements.push(
400418
new iam.PolicyStatement({

packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-create-cluster.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,3 +2009,89 @@ test('Create Cluster with ManagedScalingPolicy', () => {
20092009
},
20102010
});
20112011
});
2012+
2013+
test('StateMachine get correct permission', () => {
2014+
// WHEN
2015+
const step = new EmrCreateCluster(stack, 'Task', {
2016+
instances: {},
2017+
name: 'Cluster',
2018+
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
2019+
});
2020+
2021+
new sfn.StateMachine(stack, 'SM', {
2022+
definition: step,
2023+
});
2024+
2025+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
2026+
PolicyDocument: {
2027+
Statement: [
2028+
{
2029+
Action: [
2030+
'elasticmapreduce:RunJobFlow',
2031+
'elasticmapreduce:DescribeCluster',
2032+
'elasticmapreduce:TerminateJobFlows',
2033+
'elasticmapreduce:AddTags',
2034+
],
2035+
Effect: 'Allow',
2036+
Resource: '*',
2037+
},
2038+
{
2039+
Action: 'iam:PassRole',
2040+
Effect: 'Allow',
2041+
Resource: [
2042+
{ 'Fn::GetAtt': ['TaskServiceRoleBF55F61E', 'Arn'] },
2043+
{ 'Fn::GetAtt': ['TaskInstanceRoleB72072BF', 'Arn'] },
2044+
],
2045+
},
2046+
{
2047+
Sid: 'ElasticMapReduceServiceLinkedRole',
2048+
Action: 'iam:CreateServiceLinkedRole',
2049+
Effect: 'Allow',
2050+
Resource: {
2051+
'Fn::Join': ['', [
2052+
'arn:',
2053+
{ Ref: 'AWS::Partition' },
2054+
':iam::*:role/aws-service-role/elasticmapreduce.amazonaws.com*/AWSServiceRoleForEMRCleanup*',
2055+
]],
2056+
},
2057+
Condition: {
2058+
StringEquals: {
2059+
'iam:AWSServiceName': [
2060+
'elasticmapreduce.amazonaws.com',
2061+
'elasticmapreduce.amazonaws.com.cn',
2062+
],
2063+
},
2064+
},
2065+
},
2066+
{
2067+
Action: 'iam:PassRole',
2068+
Effect: 'Allow',
2069+
Resource: {
2070+
'Fn::GetAtt': ['TaskAutoScalingRoleD06F8423', 'Arn'],
2071+
},
2072+
},
2073+
{
2074+
Action: ['events:PutTargets', 'events:PutRule', 'events:DescribeRule'],
2075+
Effect: 'Allow',
2076+
Resource: {
2077+
'Fn::Join': ['', [
2078+
'arn:',
2079+
{ Ref: 'AWS::Partition' },
2080+
':events:',
2081+
{ Ref: 'AWS::Region' },
2082+
':',
2083+
{ Ref: 'AWS::AccountId' },
2084+
':rule/StepFunctionsGetEventForEMRRunJobFlowRule',
2085+
]],
2086+
},
2087+
},
2088+
],
2089+
Version: '2012-10-17',
2090+
},
2091+
Roles: [
2092+
{
2093+
Ref: 'SMRole49C19C48',
2094+
},
2095+
],
2096+
});
2097+
});

0 commit comments

Comments
 (0)