'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.

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. what is the issue here?



Solution 1:[1]

require('http');

That is an HTTP client -- not an HTTPS client.

Specifying port 443 doesn't result in an HTTPS request, even though port 443 is the assigned port for HTTPS. It just makes an ordinary HTTP request against destination port 443.

This isn't a valid thing to do, so CloudFront is returning a Bad Request error.

You almost certainly want to require('https');.

Solution 2:[2]

I am facing the same error, I solved this by removing the body from my postman request.

Solution 3:[3]

I have seen this problem before. It happens due to the following reasons,

  1. Invalid Protocol (using http instead of https)
  2. Unknown http verb, make sure the endpoint is having the POST implemented in your case. If you are using API gateway, make sure you have deployed it.

Solution 4:[4]

In my case, I had the same problem as @Kireeti K, where I solved this by removing the body from my postman request.

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.

Solution 5:[5]

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.
  2. The requested alternate domain name (CNAME) isn't associated with the CloudFront distribution.

(In my case, the reason was #2).

Solution 6:[6]

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. So, once I changed it, it worked fine.

Solution 7:[7]

In my case, I have a client-side load balancer when calling CloudFront. As a result, I am calling CF by IP address instead of hostName. I checked with Amazon AWS Support team, in this case, CF rejects the request and returns "403 Error, The request could be satisfied".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael - sqlbot
Solution 2 Kireeti K
Solution 3 Kannaiyan
Solution 4 roee klinger
Solution 5 RtmY
Solution 6 Dharman
Solution 7 user3550180