将变量传递给Google Cloud函数 [英] Passing Variables To Google Cloud Functions

查看:46
本文介绍了将变量传递给Google Cloud函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了使用HTTP触发器在Beta Python 3.7运行时中编写Google Cloud Function的工作.现在,我试图弄清楚在调用它时如何将字符串变量传递给我的函数.我已经阅读了文档,但是还没有找到任何东西.

I've just finished writing a Google Cloud Function in the Beta Python 3.7 runtime with an HTTP trigger. Now I'm trying to figure out how to pass a string variable to my function when calling it. I've read the documentation but I haven't found anything on this.

我的触发器类似于:

https://us-central1-*PROJECT_ID*.cloudfunctions.net/*FUNCTION_NAME*

我误解了云功能的工作原理吗?您甚至可以将变量传递给他们吗?

Am I misunderstanding how Cloud Functions work? Can you even pass variables to them?

推荐答案

您将变量传递给函数的方式与将变量传递给任何URL的方式相同:

You'd pass variables to the function the same way you'd pass variables to any URL:

def test(request):
    name = request.args.get('name')
    return f"Hello {name}"

$ curl -X GET https://us-central1-<PROJECT>.cloudfunctions.net/test?name=World
Hello World

2.通过POST格式:

2. Via a POST with a form:

def test(request):
    name = request.form.get('name')
    return f"Hello {name}"

$ curl -X POST https://us-central1-<PROJECT>.cloudfunctions.net/test -d "name=World"
Hello World

3.通过带有JSON的POST:

def test(request):
    name = request.get_json().get('name')
    return f"Hello {name}"

$ curl -X POST https://us-central1-<PROJECT>.cloudfunctions.net/test -d '{"name":"World"}'
Hello World

更多详细信息可以在这里找到: https://cloud.google.com/functions /docs/writing/http

More details can be found here: https://cloud.google.com/functions/docs/writing/http

这篇关于将变量传递给Google Cloud函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆