Skip to content

Commit

Permalink
Merge pull request #1618 from kyleknap/default-roles-update
Browse files Browse the repository at this point in the history
Update error logic for create-default-roles
  • Loading branch information
kyleknap committed Nov 4, 2015
2 parents 3f6c671 + 00c5989 commit 94dcdfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions awscli/customizations/datapipeline/createdefaultroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
DATAPIPELINE_DEFAULT_RESOURCE_ROLE_ASSUME_POLICY
from awscli.customizations.commands import BasicCommand
from awscli.customizations.datapipeline.translator \
import display_response, dict_to_string, get_region
import display_response, dict_to_string, get_region, remove_cli_error_event
from botocore.exceptions import ClientError

LOG = logging.getLogger(__name__)
Expand All @@ -35,12 +35,12 @@ class CreateDefaultRoles(BasicCommand):
DESCRIPTION = ('Creates the default IAM role ' +
DATAPIPELINE_DEFAULT_SERVICE_ROLE_NAME + ' and ' +
DATAPIPELINE_DEFAULT_RESOURCE_ROLE_NAME +
'\n which are used while creating an EMR cluster. '
'\nIf the roles do not exist, create-default-roles '
' which are used while creating an EMR cluster.\n'
'If the roles do not exist, create-default-roles '
'will automatically create them and set their policies.'
'\nIf these roles are already '
' If these roles are already '
'created create-default-roles'
'will not update their policies.'
' will not update their policies.'
'\n')

def __init__(self, session, formatter=None):
Expand All @@ -53,6 +53,7 @@ def _run_main(self, parsed_args, parsed_globals, **kwargs):
self._iam_client = self._session.create_client(
'iam', self._region, self._endpoint_url,
parsed_globals.verify_ssl)
remove_cli_error_event(self._iam_client)
return self._create_default_roles(parsed_args, parsed_globals)

def _create_role(self, role_name, role_arn, role_policy):
Expand Down
10 changes: 10 additions & 0 deletions awscli/customizations/datapipeline/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def get_region(session, parsed_globals):
return region


def remove_cli_error_event(client):
"""This unregister call will go away once the client switchover
is done, but for now we're relying on S3 catching a ClientError
when we check if a bucket exists, so we need to ensure the
botocore ClientError is raised instead of the CLI's error handler.
"""
client.meta.events.unregister(
'after-call', unique_id='awscli-error-handler')


# Method to display the response for a particular CLI operation
def display_response(session, operation_name, result, parsed_globals):
cli_operation_caller = CLIOperationCaller(session)
Expand Down

0 comments on commit 94dcdfc

Please sign in to comment.