【发布时间】:2022-10-21 04:32:15
【问题描述】:
我已经通过 CloudFormation 设置了一个具有 OpenAPI 规范和 Lambda 集成的 API 网关。它已正确部署并显示所有方法和资源等。 如果我调用我的 POST、PATCH 或 DELETE 方法之一(甚至是 OPTIONS!),它们会成功到达我的 lambda 函数并按预期返回。 但是,一旦我使用 GET 或 HEAD 方法调用我的一个端点——无论是存在的 GET 端点,还是不存在的 GET 方法(例如 /foobar),我得到的只是一个 HTTP 403HTML内容而不是 JSON:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: ju-yNp9QlyjqrAFHC3xR9DkO0N9DaPK2BcVQlpeswPMEerwErwdDUw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
标头仅包括X-Cache: Error from Cloudfront,没有常规API 网关标头,例如x-amzn-ErrorType。我相信该请求甚至没有到达我的 API 网关。
我正在调用我的xxxxxxxx.execute-api.eu-west-1.amazonaws.com URL,所以 CloudFront 没有手动放在前面,但我猜 API 网关本身使用 CloudFront。是否因某种原因为我的 GET 端点启用了缓存?在我的 API 网关阶段参数中,“API 缓存”被禁用,我找不到与 CloudFront 或缓存远程相关的任何其他内容。
我的 API 及其集成如下所示:
/mypath:
get:
x-amazon-apigateway-integration:
type: aws_proxy
passthroughBehavior: when_no_match
httpMethod: POST
uri: arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:xxxxxxxxx:function:${stageVariables.LambdaName}/invocations
requestParameters: {}
responses:
'200':
statusCode: '200'
'400':
statusCode: '400'
这种集成适用于所有非 GET 请求,但会导致所有 GET 请求出现这种奇怪的错误。 我有 DEFAULT_4XX 响应,这也适用于所有其他方法,例如 POST /something-non-existing - 这使得我的自定义响应很好。我没有在任何地方配置 HTML 内容,为什么会发生这种情况?
【问题讨论】:
标签: aws-api-gateway amazon-cloudfront