def worker_thread()

in src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/main.py [0:0]


def worker_thread(
        account_id,
        sts,
        config,
        s3,
        cache,
        updated_kms_bucket_dict):
    """
    The Worker thread function that is created for each account
    in which CloudFormation create_stack is called
    """
    LOGGER.debug("%s - Starting new worker thread", account_id)

    organizations = Organizations(
        role=boto3,
        account_id=account_id
    )
    ou_id = organizations.get_parent_info().get("ou_parent_id")

    account_state = is_account_in_invalid_state(ou_id, config.config)
    if account_state:
        LOGGER.info("%s %s", account_id, account_state)
        return

    account_path = organizations.build_account_path(
        ou_id,
        [],  # Initial empty array to hold OU Path,
        cache
    )
    try:
        role = ensure_generic_account_can_be_setup(
            sts,
            config,
            account_id
        )

        # Regional base stacks can be updated after global
        for region in list(
                set([config.deployment_account_region] + config.target_regions)):
            # Ensuring the kms_arn and bucket_name on the target account is
            # up-to-date
            parameter_store = ParameterStore(region, role)
            parameter_store.put_parameter(
                'kms_arn', updated_kms_bucket_dict[region]['kms'])
            parameter_store.put_parameter(
                'bucket_name', updated_kms_bucket_dict[region]['s3_regional_bucket'])
            cloudformation = CloudFormation(
                region=region,
                deployment_account_region=config.deployment_account_region,
                role=role,
                wait=True,
                stack_name=None,
                s3=s3,
                s3_key_path="adf-bootstrap/" + account_path,
                account_id=account_id
            )
            try:
                cloudformation.create_stack()
                if region == config.deployment_account_region:
                    cloudformation.create_iam_stack()
            except GenericAccountConfigureError as error:
                if 'Unable to fetch parameters' in str(error):
                    LOGGER.error(
                        '%s - Failed to update its base stack due to missing parameters '
                        '(deployment_account_id or kms_arn), ensure this account has been '
                        'bootstrapped correctly by being moved from the root into an '
                        'Organizational Unit within AWS Organizations.',
                        account_id,
                    )
                raise Exception from error

    except GenericAccountConfigureError as generic_account_error:
        LOGGER.info(generic_account_error)
        return