Skip to content

try to get_role, but fall back to role from regex #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 20, 2018

Conversation

andremoeller
Copy link
Contributor

@andremoeller andremoeller commented Jul 19, 2018

Issue #, if available: #291

Description of changes:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated the changelog with a description of my changes (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@andremoeller andremoeller requested a review from laurenyu July 19, 2018 01:26
try:
role = self.boto_session.client('iam').get_role(RoleName=role_name)['Role']['Arn']
except ClientError:
LOGGER.warning("Couldn't call 'get_role' to get Role ARN from role name {}.".format(role_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd include a note here that this will exclude a role's path if it has one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andremoeller @laurenyu
AmazonSageMakerFullAccess that is a managed policy for SageMaker (see doc) does not allow iam:GetRole. The line in tryalways fail and goes to except if users attach only AmazonSageMakerFullAccess to the role; get_role() does not work. Could you consider another implementation for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harusametime

You're right -- in that case. The purpose of this is to attempt to get the role using iam:GetRole, but never to fail in this case -- not all users will only be using AmazonSageMakerFullAccess policy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. Thanks!

sess.boto_session.client('iam').get_role.side_effect = ClientError('Bad permissions!', {})

actual = sess.get_caller_identity_arn()
assert actual == 'arn:aws:iam::369233609183:user/mia'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to also test if the logger does warn?

laurenyu
laurenyu previously approved these changes Jul 19, 2018
Andre Moeller added 2 commits July 19, 2018 15:04
@codecov-io
Copy link

Codecov Report

Merging #305 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #305      +/-   ##
==========================================
+ Coverage   92.69%   92.75%   +0.06%     
==========================================
  Files          50       50              
  Lines        3463     3466       +3     
==========================================
+ Hits         3210     3215       +5     
+ Misses        253      251       -2
Impacted Files Coverage Δ
src/sagemaker/session.py 88.56% <100%> (+0.09%) ⬆️
src/sagemaker/local/image.py 87.68% <0%> (+0.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ff1e23...9174c00. Read the comment docs.

@andremoeller andremoeller merged commit 2fa160c into aws:master Jul 20, 2018
@andremoeller andremoeller deleted the get-execution-role-fix branch July 20, 2018 05:13
knakad added a commit to knakad/sagemaker-python-sdk that referenced this pull request Dec 4, 2019
knakad added a commit that referenced this pull request Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants