简体   繁体   English

Cloud Front:无法满足请求

[英]Cloud Front : The request could not be satisfied

I am coming across this problem, i have a chat server which needs to communicate to the lambda service hosted in aws, but cloud front throws the following error.我遇到了这个问题,我有一个聊天服务器需要与 aws 中托管的 lambda 服务进行通信,但云端抛出以下错误。

BODY: <!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>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Bad request.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: h5kPdVnMXwh-P7e7mxQ5LL1gj9fAupp_MNAPxmxufI74W4WhE_MByw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

This is how my request goes in application.这就是我的请求在申请中的方式。

const options = {
    hostname: 'xxx.uat.com',
    port : '443',        
    path: '/qa/addMessage',
    method: 'POST'
};
const req = http.request(options, (res) => {
}

the chat server.js is hosted in ec2.聊天 server.js 托管在 ec2 中。 what is the issue here?这里有什么问题?

require('http');

That is an HTTP client -- not an HTTPS client.那是一个 HTTP 客户端——而不是一个 HTTPS 客户端。

Specifying port 443 doesn't result in an HTTPS request, even though port 443 is the assigned port for HTTPS.指定端口 443 不会产生 HTTPS 请求,即使端口 443 是为 HTTPS 分配的端口。 It just makes an ordinary HTTP request against destination port 443.它只是针对目标端口 443 发出一个普通的 HTTP 请求。

This isn't a valid thing to do, so CloudFront is returning a Bad Request error.这不是有效的做法,因此 CloudFront 返回Bad Request错误。

You almost certainly want to require('https');你几乎肯定想要require('https'); . .

I have seen this problem before.我以前见过这个问题。 It happens due to the following reasons,它的发生是由于以下原因,

  1. Invalid Protocol (using http instead of https)无效的协议(使用 http 而不是 https)
  2. Unknown http verb, make sure the endpoint is having the POST implemented in your case.未知的 http 动词,请确保端点在您的案例中实施了 POST。 If you are using API gateway, make sure you have deployed it.如果您正在使用 API 网关,请确保您已部署它。

我面临同样的错误,我通过从邮递员请求中删除正文解决了这个问题。

In my case, I had the same problem as @Kireeti K, where I solved this by removing the body from my postman request.就我而言,我遇到了与@Kireeti K 相同的问题,我通过从postman请求中删除正文来解决此问题。

it seems that Cloudfront throws an error if you send a GET request with a body, if you want to use the body, you will need to change your method to something else than GET , for me POST worked perfectly, the error was gone and I was able to read the body.如果您发送带有正文的GET请求,Cloudfront 似乎会抛出错误,如果您想使用正文,则需要将您的方法更改为GET之外的其他方法,对我来说POST工作得很好,错误消失了,我能够阅读身体。

I encountered the same problem, this thread worked for me.我遇到了同样的问题, 这个线程对我有用。

This error message:此错误消息:

"The request could not be satisfied. Bad Request." “无法满足请求。错误的请求。”

is from the client and the error can occur due to one of the following reasons:来自客户端,错误可能由于以下原因之一而发生:

  1. The request is initiated over HTTP, but the CloudFront distribution is configured to allow only HTTPS requests.该请求通过 HTTP 发起,但 CloudFront 分配配置为仅允许 HTTPS 请求。
  2. The requested alternate domain name (CNAME) isn't associated with the CloudFront distribution.请求的备用域名 (CNAME) 与 CloudFront 分配无关。

(In my case, the reason was #2). (就我而言,原因是#2)。

For me the problem was that, I restarted the EC2 which changed the Instance ID, but my cloudfront origin was still pointing to the previous ID.对我来说,问题是,我重新启动了更改实例 ID 的 EC2,但我的 Cloudfront 源仍然指向以前的 ID。 So, once I changed it, it worked fine.所以,一旦我改变了它,它就可以正常工作。

In my case, I have a client-side load balancer when calling CloudFront.就我而言,我在调用 CloudFront 时有一个客户端负载均衡器。 As a result, I am calling CF by IP address instead of hostName.因此,我通过 IP 地址而不是主机名调用 CF。 I checked with Amazon AWS Support team, in this case, CF rejects the request and returns "403 Error, The request could be satisfied".我与 Amazon AWS Support 团队核实,在这种情况下,CF 拒绝请求并返回“403 错误,请求可以得到满足”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM