in functions/source/account_create.py [0:0]
def lambda_handler(event, context):
'''Parse the previous event and trigger next account creation'''
pp_id = None
create_new_account = False
if 'RequestType' in event:
event_source = 'cloudformation'
create_new_account = process_cft_event(event)
elif 'Records' in event:
event_source = 'dynamodb'
create_new_account = process_dynamodb_event(event)
elif event['source'] == 'aws.controltower':
event_source = 'controltower'
process_lifecycle_event(event)
else:
LOGGER.warning('Unknown Event recieved: %s', event)
if create_new_account:
(pp_id, input_params) = provision_new_account()
if pp_id.startswith('pp-'):
(status, message) = get_pp_status(pp_id)
iteration = 1
while iteration <= 3:
if status != 'UNDER_CHANGE':
sc_initial_failure(input_params, message)
iteration = 4
else:
LOGGER.info('Check-%s: %s', iteration, status)
sleep(30)
(status, message) = get_pp_status(pp_id)
iteration += 1
elif len(input_params) == 0:
LOGGER.info('Provisioning the batch completed')
pass_items = get_items('SUCCEEDED')
fail_items = get_items('SUCCEEDED', True)
fail_count = len(fail_items)
invld_items = get_items('INVALID')
LOGGER.info('SUCCESS: %s Entries, %s', len(pass_items), pass_items)
LOGGER.info('TOTAL FAILED: %s Entries, %s', fail_count, fail_items)
LOGGER.warning('%s of %s FAILED DUE TO INVALID Entires, %s',
len(invld_items), fail_count, invld_items)
else:
sc_initial_failure(input_params, pp_id)
LOGGER.info('SC Product Launch Failed: %s', input_params)
if event_source == 'cloudformation':
response = {}
cfnresource.send(event, context, cfnresource.SUCCESS,
response, "CustomResourcePhysicalID")