【问题标题】:How to call an HTTP cloud function using Python in AWS Lambda?如何在 AWS Lambda 中使用 Python 调用 HTTP 云函数?
【发布时间】:2021-08-25 08:40:56
【问题描述】:

我正在尝试通过 lambda 函数 (Python) 将 JSON 数据从 AWS S3 发送到谷歌云函数。添加到 S3 的 JSON 文件将触发 lambda 函数,该函数将执行 POST 事件,将 JSON 文件的内容发送到谷歌云函数。

我知道这是可能的,因为它在this 帖子中被引用,但没有解释或代码让我开始。

我知道如何设置 lambda 函数,但我不知道如何创建 POST 事件以将数据发送到云函数的 URL。有人能指出我正确的方向吗?

【问题讨论】:

  • 这是一个简单的 HTTP 调用。不再。底层平台不会改变通信的性质。或者你的问题在别处。请解释一下。

标签: python amazon-s3 aws-lambda google-cloud-functions


【解决方案1】:

确保您的云函数是 onRequest 类型,因为您无法在没有 Firebase 模块的情况下调用 onCall

onRequest 示例:

exports.addMessage = functions.https.onRequest(async (req, res) => {
  // Grab the text parameter.
  const original = req.query.text;
  // Push the new message into Firestore using the Firebase Admin SDK.
  const writeResult = await admin.firestore().collection('messages').add({original: original});
  // Send back a message that we've successfully written the message
  res.json({result: `Message with ID: ${writeResult.id} added.`});
});

如何调用云函数: https://firebase.google.com/docs/functions/http-events#invoke_an_http_function

【讨论】:

    猜你喜欢
    • 2021-09-19
    • 1970-01-01
    • 2021-06-05
    • 2019-10-27
    • 2018-01-29
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多