Skip to content

Commit d057738

Browse files
authored
Merge pull request #269 from awslabs/non-orgs-fix
Fix the error with non-orgs based manual account list
2 parents 19b1cb6 + 27e3d9f commit d057738

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

data-collection/deploy/account-collector.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ Resources:
110110
111111
import boto3
112112
113-
ROLE_NAME = os.environ['ROLE_NAME']
114-
RESOURCE_PREFIX = os.environ['RESOURCE_PREFIX']
115-
MANAGEMENT_ACCOUNT_IDS = os.environ['MANAGEMENT_ACCOUNT_IDS']
116-
BUCKET = os.environ['BUCKET_NAME']
113+
ROLE_NAME = os.environ.get('ROLE_NAME')
114+
RESOURCE_PREFIX = os.environ.get('RESOURCE_PREFIX')
115+
MANAGEMENT_ACCOUNT_IDS = os.environ.get('MANAGEMENT_ACCOUNT_IDS')
116+
BUCKET = os.environ.get('BUCKET_NAME')
117117
PREDEF_ACCOUNT_LIST_KEY = os.environ.get('PREDEF_ACCOUNT_LIST_KEY')
118118
LINKED_ACCOUNT_LIST_KEY = os.environ.get('LINKED_ACCOUNT_LIST_KEY')
119119
PAYER_ACCOUNT_LIST_KEY = os.environ.get('PAYER_ACCOUNT_LIST_KEY')
@@ -185,14 +185,14 @@ Resources:
185185
defined_accounts, ext = get_defined_list(BUCKET, PREDEF_ACCOUNT_LIST_KEY)
186186
try:
187187
if defined_accounts:
188-
logger.info(f'Using defined account list found in s3://{BUCKET}/{PREDEF_ACCOUNT_LIST_KEY} instead of payer organization')
188+
logger.info(f'Using defined account list found in s3://{BUCKET}/{PREDEF_ACCOUNT_LIST_KEY}{ext} instead of payer organization')
189189
for account_data in defined_accounts:
190190
if ext == "json":
191191
account = json.loads(account_data)
192192
yield format_account(account['account_id'], account['account_name'], account['payer_id'])
193193
else:
194194
account = account_data.split(',')
195-
yield format_account(account[0], account[1], account[2])
195+
yield format_account(account[0].strip(), account[1].strip(), account[2].strip())
196196
else:
197197
logger.info('Using payer organization for the account list')
198198
excluded_accounts = get_from_bucket(BUCKET, EXCLUDED_ACCOUNT_LIST_KEY)
@@ -210,13 +210,13 @@ Resources:
210210
continue
211211
yield format_account(account.get('Id'), account.get('Name'), org_account['payer_id'])
212212
except Exception as exc: #pylint: disable=broad-exception-caught
213-
logger.error(f'{org_account}: {exc}')
213+
logger.error( f'{type(exc).__name__}: When trying to build linked account list. {exc} ')
214214
215215
def get_defined_list(bucket, key):
216216
s3 = boto3.client("s3")
217217
exts = [".json", ".csv"]
218218
for ext in exts:
219-
accts = get_from_bucket(bucket, key, s3)
219+
accts = get_from_bucket(bucket, key+ext, s3)
220220
if accts:
221221
return accts, ext
222222
logger.debug(f'Predefined account list not retrieved or not being used')

0 commit comments

Comments
 (0)