[英]API gateway not invoking a chalice endpoint
I am trying to expose a very simple endpoint using chalice and deploy it to AWS Lambda (not using Chalice CLI though).我正在尝试使用 chalice 公开一个非常简单的端点并将其部署到 AWS Lambda(虽然不使用 Chalice CLI)。 Then I create the corresponding aws lambda function by zipping up the code and uploading it.然后我通过压缩代码并上传它来创建相应的aws lambda function。 Then I create the api gateway manually and point it to the Lambda, doesn't matter how hard I try, I can't make the Lambda API to get called.然后我手动创建 api 网关并将其指向 Lambda,无论我多么努力,我都无法让 Lambda API 被调用。
Python code 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 gateway route Api 网关路由
Output Output
url: https://lw751abcd.execute-api.us-east-1.amazonaws.com/test
{"Code":"InternalServerError","Message":"Unknown request."}
What am I missing here?我在这里错过了什么?
updated my code to below but still doesn't work.将我的代码更新到下面但仍然不起作用。
@app.route('/test/{proxy+}', methods=['GET'])
def hello_world():
return {
"isBase64Encoded": true,
"statusCode": 200,
"headers": { "status": "200"},
"multiValueHeaders": { },
"body": {
"hello world"
}
}
The issue was that while creating api gateway, I was choosing HTTP
instead of REST
as type.问题是在创建 api 网关时,我选择HTTP
而不是REST
作为类型。 With API type as REST
, everything was working as expected and I didn't have to worry about request and response body. API 类型为REST
,一切都按预期工作,我不必担心请求和响应正文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.