从 google 云函数触发 DAG

Trigger DAG from google cloud function

当文件到达基于云 composer documentation 在 Python

中使用 Cloud Function

我一直无法让它工作,每次它触发时,函数returns将这条消息记录到日志

Exception: Bad response from application: 400 / {'Date': 'Mon, 30 Dec 2019 18:07:02 GMT', 'Content-Type': 'text/html', 'Content-Length': '192', 'Server': 'gunicorn/19.9.0', 'Via': '1.1 google', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000'} / '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>400 Bad Request</title>\n<h1>Bad Request</h1>\n<p>The browser (or proxy) sent a request that this server could not understand.</p>\n'

请求 URL s¡generate 和 open id token 似乎是正确的 错误出现在代码的最后部分

resp = requests.request(
    method, url,
    headers={'Authorization': 'Bearer {}'.format(
        google_open_id_connect_token)}, **kwargs)
if resp.status_code == 403:
    raise Exception('Service account {} does not have permission to '
                    'access the IAP-protected application.'.format(
                        signer_email))
elif resp.status_code != 200:
    raise Exception(
        'Bad response from application: {!r} / {!r} / {!r}'.format(
            resp.status_code, resp.headers, resp.text))

谢谢

错误代码400 Bad Request reflected in the initial question more often corresponds to the client side problem, indeed the input parameters for DAG triggering should be inspected as a first, the function that invokes IAP call in the code example:

def make_iap_request(url, client_id, method='GET', **kwargs)

确保您已通过 requirements.txt 文件应用 运行 针对受 IAP 保护 URL 所需的依赖项。

不要忘记验证传递给此函数的基本参数:

url: The Identity-Aware Proxy-protected URL to fetch.

client_id: The client ID used by Identity-Aware Proxy.

到目前为止,我还没有找到更好的关于触发 DAG 的实践经验,然后由 @Jacob Ferriero in his great article 解释。