0

我正在尝试使用 chalice 公开一个非常简单的端点并将其部署到 AWS Lambda(虽然不使用 Chalice CLI)。然后我通过压缩代码并上传它来创建相应的 aws lambda 函数。然后我手动创建 api 网关并将其指向 Lambda,无论我多么努力,我都无法让 Lambda API 被调用。

Python代码

from chalice import Chalice, Response, BadRequestError, ChaliceViewError, NotFoundError
app = Chalice(app_name='test-app')
@app.route('/test', methods=['GET'])
def hello_world():
    return {
        "hello world"
    }

Api网关路由

在此处输入图像描述

输出

url: https://lw751abcd.execute-api.us-east-1.amazonaws.com/test
{"Code":"InternalServerError","Message":"Unknown request."}

我在这里想念什么?

更新

将我的代码更新到下面,但仍然无法正常工作。

@app.route('/test/{proxy+}', methods=['GET'])
def hello_world():
    return {
    "isBase64Encoded": true,
    "statusCode": 200,
    "headers": { "status": "200"},
    "multiValueHeaders": { },
    "body": {
        "hello world"
    }
}
4

1 回答 1

0

问题是在创建 api gateway 时,我选择HTTP而不是REST作为类型。使用 API 类型 as REST,一切都按预期工作,我不必担心请求和响应正文。

于 2020-05-28T12:48:46.680 回答