1
votes

Trying to set up API gateway API (to a Lambda service) with an edge optimized custom domain. Set up custom domain: custom domain setup on API gateway

A call to the original AWS API URL (https://****.execute-api.****.amazonaws.com/prod) works perfectly.

But a call to either the ****.cloudfront.net URL or the custom domain (api.****.com) returns a Bad Request:

$ curl https://****.cloudfront.net/**** -H "Host:api.****.com"
<!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: ***==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

(Spoofing the Host: header on that request)

In my domain's DNS settings I've set up a CNAME record to point to the cloudfront URL, and it seems to be working OK.

(On the custom domain I also have an SSL problem I can't get through, but I'd like to get this resolved first...)

1
So you converted edge optimized endpoints to regional optimized to make it work? I'm facing a similar issue and asked it here: stackoverflow.com/questions/57944161/… - Krishna Mohan

1 Answers

0
votes

Whitelist the Host header for forwarding in the Cache Behavior settings. This makes Cloudfront pass it through to your custom origin.

You can get more info on Cloudfront's cache header behavior here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html