Skip to content

Commit

Permalink
Merge pull request #120 from Yelp/spark_run_aws_error
Browse files Browse the repository at this point in the history
Add error message when using spark-run with assume-aws-role
  • Loading branch information
Qmando authored Aug 15, 2023
2 parents 4007d17 + 00a2cc0 commit d62f4fe
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions service_configuration_lib/spark_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ def assume_aws_role(
Checks that a web identity token is available, and if it is,
get an aws session and return a credentials dictionary
"""
with open(key_file) as creds_file:
creds_dict = yaml.load(creds_file.read(), Loader=yaml.SafeLoader)
access_key = creds_dict['AccessKeyId']
secret_key = creds_dict['SecretAccessKey']
try:
with open(key_file) as creds_file:
creds_dict = yaml.load(creds_file.read(), Loader=yaml.SafeLoader)
access_key = creds_dict['AccessKeyId']
secret_key = creds_dict['SecretAccessKey']
except PermissionError:
log.warning(
'If using spark-run as a human, you must manually export '
'AWS session credentials first. See y/spark-run-aws-role',
)
raise
timestamp = int(time.time())
client = boto3.client('sts', aws_access_key_id=access_key, aws_secret_access_key=secret_key)
resp = client.assume_role(
Expand Down

0 comments on commit d62f4fe

Please sign in to comment.