Skip to content

Commit

Permalink
Merge pull request #183 from noqdev/bugfix/en-1814-boto3-session-not-…
Browse files Browse the repository at this point in the history
…initialized

EN-1814: Defensive coding if boto3_session is not initialized
  • Loading branch information
mdaue2 authored Mar 2, 2023
2 parents 530ba5a + ada2baa commit 922167d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions iambic/config/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ def __init__(self, repo_dir: str):
self.default_region = "us-east-1"
try:
self.boto3_session = boto3.Session(region_name=self.default_region)
except Exception:
self.boto3_session = None
except Exception as exc:
log.error(f"Unable to access your AWS account: {exc}")
sys.exit(1)

self.autodetected_org_settings = {}
self.existing_role_template_map = {}
self.aws_account_map = {}
Expand All @@ -215,17 +217,13 @@ def __init__(self, repo_dir: str):
else:
self.hub_account_id = None

if self.boto3_session:
try:
default_caller_identity = self.boto3_session.client(
"sts"
).get_caller_identity()
caller_arn = get_identity_arn(default_caller_identity)
default_hub_account_id = caller_arn.split(":")[4]
except (AttributeError, IndexError, NoCredentialsError, ClientError):
default_hub_account_id = None
default_caller_identity = {}
else:
try:
default_caller_identity = self.boto3_session.client(
"sts"
).get_caller_identity()
caller_arn = get_identity_arn(default_caller_identity)
default_hub_account_id = caller_arn.split(":")[4]
except (AttributeError, IndexError, NoCredentialsError, ClientError):
default_hub_account_id = None
default_caller_identity = {}

Expand Down

0 comments on commit 922167d

Please sign in to comment.