def global_table_create()

in source/cfn-global-table/cfn-global-table.py [0:0]


def global_table_create(event, context):
    logger.info(json.dumps(event))
    global_table_name = event['ResourceProperties']['GlobalTableName']

    try:
        resp = {'Status': 'FAILED', 'Data': {'GlobalTableName': global_table_name, 'LogGroup': context.log_group_name }}
        client = boto3.client('dynamodb')

        logger.debug('Creating DynamoDB Global Table ' + global_table_name)
        response = {}
        replication_group = []

        for region in event['ResourceProperties']['ReplicationGroupList']:
            replication_group.append({ 'RegionName': region})

        response = client.create_global_table(
            GlobalTableName=global_table_name,
            ReplicationGroup=replication_group
        )
        logger.info(response)
        resp['Reason'] = 'Created Global Table: ' + global_table_name
        resp['Status'] = 'SUCCESS'

    except client.exceptions.GlobalTableAlreadyExistsException as e:
        logger.info('Global Table already exists, falling back to update logic: ' + e.message )
        # Describe the already existing global table, so we can attempt to update instead
        response = {}
        response = client.describe_global_table(
            GlobalTableName=global_table_name
        )

        logger.debug(response)

        existing_replication_group_list = []
        for region in response['GlobalTableDescription']['ReplicationGroup']:
            logger.debug('Existing Replication Group List')
            existing_replication_group_list.append(region['RegionName'])
        event['OldResourceProperties']= { 'ReplicationGroupList': existing_replication_group_list }
        response = global_table_update(event,context)
        return response

    except Exception as e:
        logger.error('Failed to create DynamoDB Global Table: ' + global_table_name)
        resp['Reason'] = 'Failed to create DynamoDB Global Table: ' + e.message 
        resp['Status'] = 'FAILED'
    
    return resp