【问题标题】:How to change the local payload when invoking a lambda in cloud9 IDE?在 cloud9 IDE 中调用 lambda 时如何更改本地有效负载?
【发布时间】:2022-10-06 23:25:35
【问题描述】:

我在 AWS Cloud9 中进行开发,并使用 Lambda 设置了一个基本的“Hello, World”API。

现在我想迭代以便 API 可以接受参数。 Cloud9 曾经有一个方便的 UI,用于在运行“本地”时修改有效负载(在 IDE 中,没有部署)。但是我找不到这个被移动的地方,并且文档仍然引用了以前的 UI。

为了测试这一点,我在我的 Lambda 中包含了一个简单的print(event),并开始修改各种组件。到目前为止,我只打印一个空字典 ({})。 我怀疑它在launch.json 中,但到目前为止我修改的所有内容都没有被拾取。如下所示

{
    \"configurations\": [
        {
            \"type\": \"aws-sam\",
            \"request\": \"direct-invoke\",
            \"name\": \"API token-to-geojson:HelloWorldFunction (python3.9)\",
            \"invokeTarget\": {
                \"target\": \"api\",
                \"templatePath\": \"token-to-geojson/template.yaml\",
                \"logicalId\": \"HelloWorldFunction\"
            },
            \"api\": {
                \"path\": \"/hello\",
                \"httpMethod\": \"get\",
                \"payload\": {
                    \"json\": {}
                }
            },
            \"lambda\": {
                \"runtime\": \"python3.9\"
            }
        },
        {
            \"type\": \"aws-sam\",
            \"request\": \"direct-invoke\",
            \"name\": \"token-to-geojson:HelloWorldFunction (python3.9)\",
            \"invokeTarget\": {
                \"target\": \"template\",
                \"templatePath\": \"token-to-geojson/template.yaml\",
                \"logicalId\": \"HelloWorldFunction\"
            },
            \"lambda\": {
                \"payload\": {
                    \"ticky\": \"tacky\"
                },
                \"environmentVariables\": {},
                \"runtime\": \"python3.9\"
            }
        }
    ]
}

    标签: aws-lambda cloud9-ide


    【解决方案1】:

    我唯一看到的是我们需要在实际的 json 数据之前添加“json”。在下面的示例中,IDE 似乎已经知道 id 是 event.id(注意 event 是处理程序的第一个参数)。

    "lambda": {
                    "payload": {
                        "json": {
                            "id": 1001
                        }
                    },
                    "environmentVariables": {}
                }
    

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多