简体   繁体   English

API 网关不调用圣杯端点

[英]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?我在这里错过了什么?

UPDATE更新

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.

相关问题 带 Dropbox 的 AWS Chalice API 超时 - AWS Chalice with Dropbox API timeout API 网关 URL(端点 ID)在“sls deploy”后更改,端点未出现在 API 网关中 - API Gateway URL (endpoint id) Changed after “sls deploy” and endpoint is not appearing in API Gateway 调用 AWS 网关 API:com.amazon.coral.service#SerializationException - Invoking AWS Gateway API: com.amazon.coral.service#SerializationException 在 CloudWatch 控制面板中显示调用 API 网关的不同用户数 - Show distinct number of users invoking API Gateway in CloudWatch dashboard AWS Cognito + API 网关 + 调用 Cognito 令牌端点 - AWS Cognito + API Gateway + Calling Cognito Token Endpoint 在 CDK 中跨不同堆栈共享 API 网关端点 URL - Sharing API gateway endpoint URL across different stacks in CDK 如何将来自 AWS API 网关的请求存储在 dynamodb 中,然后将其发送到端点 - How to store a request from AWS API Gateway in dynamodb and then send it to an endpoint 如何对 Chalice 应用程序进行异步 API 调用? - How to make an asynchronous API call to a Chalice app? output 来自亚马逊的纯文本内容 API 网关端点 - output plain text content from Amazon API gateway endpoint 在 API 网关中将 AWS Lambda 和 HTTP 端点集成在一起? - Integrating AWS Lambda and HTTP endpoint together in API Gateway?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM