From 43c7def09a6ce05753a4fd8a54da7ee98128554b Mon Sep 17 00:00:00 2001 From: Ajithesh Navaneethakrishnan Date: Mon, 6 Jun 2022 18:05:51 -0400 Subject: [PATCH] Update EMR add-steps API to accept ExecutionRoleArn --- awscli/customizations/emr/addsteps.py | 7 +++++++ awscli/customizations/emr/helptext.py | 6 ++++++ .../unit/customizations/emr/test_add_steps.py | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/awscli/customizations/emr/addsteps.py b/awscli/customizations/emr/addsteps.py index b8f0fe65803d..b816d2eee76a 100644 --- a/awscli/customizations/emr/addsteps.py +++ b/awscli/customizations/emr/addsteps.py @@ -30,6 +30,10 @@ class AddSteps(Command): 'nargs': '+', 'schema': argumentschema.STEPS_SCHEMA, 'help_text': helptext.STEPS + }, + {'name': 'execution-role-arn', + 'required': False, + 'help_text': helptext.EXECUTION_ROLE_ARN } ] @@ -48,6 +52,9 @@ def _run_main_command(self, parsed_args, parsed_globals): 'Steps': step_list } + if parsed_args.execution_role_arn is not None: + parameters['ExecutionRoleArn'] = parsed_args.execution_role_arn + emrutils.call_and_display_response(self._session, 'AddJobFlowSteps', parameters, parsed_globals) return 0 diff --git a/awscli/customizations/emr/helptext.py b/awscli/customizations/emr/helptext.py index 63d4f56a7085..985e371e6eee 100755 --- a/awscli/customizations/emr/helptext.py +++ b/awscli/customizations/emr/helptext.py @@ -506,3 +506,9 @@ 'The configuration specifies the termination idle timeout' 'threshold for an cluster.

' ) + +EXECUTION_ROLE_ARN = ( + '

You must grant the execution role the permissions needed ' + 'to access the same IAM resources that the step can access. ' + 'The execution role can be a cross-account IAM Role.

' +) \ No newline at end of file diff --git a/tests/unit/customizations/emr/test_add_steps.py b/tests/unit/customizations/emr/test_add_steps.py index c806adb9f9e9..1087bf19e9b3 100644 --- a/tests/unit/customizations/emr/test_add_steps.py +++ b/tests/unit/customizations/emr/test_add_steps.py @@ -255,6 +255,27 @@ def test_streaming_step_with_default_fields(self): cmd=cmd, expected_result=expected_result, expected_result_release=expected_result_release) + def test_step_with_execution_role_arn(self): + cmd = self.prefix + 'Type=Streaming,' + self.STREAMING_ARGS + cmd += ' --execution-role-arn arn:aws:iam::123456789010:role/sample ' + expected_result = { + 'ExecutionRoleArn': 'arn:aws:iam::123456789010:role/sample', + 'JobFlowId': 'j-ABC', + 'Steps': [ + {'Name': 'Streaming program', + 'ActionOnFailure': 'CONTINUE', + 'HadoopJarStep': self.STREAMING_HADOOP_SCRIPT_RUNNER_STEP + } + ] + } + expected_result_release = copy.deepcopy(expected_result) + expected_result_release['Steps'][0]['HadoopJarStep'] = \ + self.STREAMING_HADOOP_COMMAND_RUNNER_STEP + + self.assert_params_for_ami_and_release_based_clusters( + cmd=cmd, expected_result=expected_result, + expected_result_release=expected_result_release) + def test_streaming_step_missing_args(self): cmd = self.prefix + 'Type=Streaming' expected_error_msg = '\naws: error: The following ' + \