def create_stacks()

in aws/solutions/StackSetsResource/FunctionCode/lambda_function.py [0:0]


def create_stacks(set_region, set_name, accts, regions, param_overrides,
                  ops_prefs):
    # Wrapper for create_stack_instances
    sleep_time = 15
    retries = 60
    this_try = 0

    logger.info("Creating stack instances with op prefs {}".format(ops_prefs))
    logger.debug("StackSetName: {}, Accounts: {}, Regions: {}, ParameterOverrides: {}".format(
        set_name, accts, regions, param_overrides))

    while True:
        try:
            client = boto3.client('cloudformation', region_name=set_region)
            response = client.create_stack_instances(
                StackSetName=set_name,
                Accounts=accts,
                Regions=regions,
                ParameterOverrides=param_overrides,
                OperationPreferences=ops_prefs,
                # OperationId='string'
            )
            return response
        except ClientError as e:
            if e.response['Error']['Code'] == 'OperationInProgressException':
                this_try += 1
                if this_try == retries:
                    logger.warning("Failed to create stack instances after {} tries".format(this_try))
                    raise Exception("Error creating stack instances: {}".format(e))
                else:
                    logger.warning(
                        "Create stack instances operation in progress for {} in {}. Sleeping for {} seconds.".format(
                            set_name, set_region, sleep_time))
                    sleep(sleep_time)
                    continue
            elif e.response['Error']['Code'] == 'Throttling':
                this_try += 1
                if this_try == retries:
                    logger.warning("Failed to create stack instances after {} tries".format(this_try))
                    raise Exception("Error creating stack instances: {}".format(e))
                else:
                    logger.warning(
                        "Throttling exception encountered while creating stack instances. Backing off and retyring. " 
                        "Sleeping for {} seconds.".format(sleep_time))
                    sleep(sleep_time)
                    continue
            elif e.response['Error']['Code'] == 'StackSetNotFoundException':
                raise Exception(
                    "No StackSet matching {} found in {}. You must create before creating stack instances.".format(
                        set_name, set_region))
            else:
                raise Exception("Error creating stack instances: {}".format(e))