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

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

    Args:
        custom_bucket (Optional[str]): 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.
        cfngin_bucket_region (str): The contents of the
            ``cfngin_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 = cfngin_bucket_region
    return region or provider_region