Can I get an example of how to connect a lambda function to a domain name?

Viewed 132

I've been wasting about 12 hours going in circles in what seems like this:

enter image description here

I am trying to just make a simple static landing page in lambda and hook the root of a domain to it.

The landing page works, but api gateway didn't because AWS doesn't seem to set permissions properly by default ("internal server error" with API gateway and lambda on AWS) but now the gateway link works.

So the next steps were the following:

  • add a custom domain name in the api gateway
  • add the api mapping in the custom domain name
  • in route 53, create a wildcard certificate with *.domain.com and domain.com
  • create an A record that points to the api gateway with domain.com
  • create a CNAME record that points to the A record

and I get an error 403 with absolutely nothing in the log. I log both 'default' and '$default' stages in the api gateway.

I read https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-403-error-lambda-authorizer/ which is all about looking at what's in the logs...

and I find the doc is both everywhere and nowhere because it's built as chunks of 'do this' and 'do that' without ever painting a whole picture of how each piece is connected to the other, or any graph with the hierarchy of services, etc. Reminds me of code that works only when you follow the example documented and breaks otherwise.

I'm sure I'm doing something wrong, but given the lack of logs and lack of cohesive documentation, I have no idea about the problem.

Not to mention that http doesn't even connect, just https.

Can anyone outline the steps needed to achieve this? essentially: [http|https]://(www).domain.com -> one lambda function

1 Answers

You cannot use API Gateway for an HTTP request; it only supports HTTPS.

From the Amazon API Gateway FAQs (emphasis mine):

Q: Can I create HTTPS endpoints? Yes, all of the APIs created with Amazon API Gateway expose HTTPS endpoints only. Amazon API Gateway does not support unencrypted (HTTP) endpoints. By default, Amazon API Gateway assigns an internal domain to the API that automatically uses the Amazon API Gateway certificate. When configuring your APIs to run under a custom domain name, you can provide your own certificate for the domain.

You can use CloudFront to automatically redirect HTTP to HTTPS. How do I set up API Gateway with my own CloudFront distribution? provides a pretty simple walkthrough of connecting an API Gateway to CloudFront (you can skip the API Gateway portion and use the one you created). The important thing you'll need to do that is not in that document is to select Redirect HTTP to HTTPS.

If you truly need HTTP traffic you're probably going to need to go with an ALB.

Related