def select_bucket_region(custom_bucket, hook_region, stacker_bucket_region,
    provider_region):
    """Returns the appropriate region to use when uploading functions.

    Select the appropriate region for the bucket where lambdas are uploaded in.

    Args:
        custom_bucket (str, None): The custom bucket name provided by the
            `bucket` kwarg of the aws_lambda hook, if provided.
        hook_region (str): The contents of the `bucket_region` argument to
            the hook.
        stacker_bucket_region (str): The contents of the
            `stacker_bucket_region` global setting.
        provider_region (str): The region being used by the provider.

    Returns:
        str: The appropriate region string.
    """
    region = None
    if custom_bucket:
        region = hook_region
    else:
        region = stacker_bucket_region
    return region or provider_region
