-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Figure out how to serve an AWS Lambda function with a Function URL from a custom subdomain #1
Comments
I'm going to first try setting up a CloudFront distribution. If I can get that running in front of a Lambda URL I'll have solved half the problem - the other half will be figuring out how to point a custom domain at CloudFront. Some useful docs:
|
I'm going to skim through and make notes on the whole Amazon CloudFront developer guide: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html |
It's basically a caching CDN like Fastly. You don't pay for transfer between your Amazon-hosted application servers and CloudFront, but you do pay for bandwidth served between CloudFront and end users. |
Sounds like |
CloudFront can also run "Lambda@Edge" functions, but these can currently only be written in JavaScript. |
You can chose a cheaper plan that doesn't have POP locations in some countries: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PriceClass.html |
https://fnkvspusjrl5dxytaxnuwidxem0hverw.lambda-url.us-east-1.on.aws/ is the function URL I want to use. |
https://d81numqdze872.cloudfront.net/ is not working yet. |
OK it works now. |
Hitting the same page twice with
|
I don't think querystring parameters are being passed through correctly. https://d81numqdze872.cloudfront.net/fixtures/no_primary_key?_facet=a ignores the facet request. But https://fnkvspusjrl5dxytaxnuwidxem0hverw.lambda-url.us-east-1.on.aws/fixtures/no_primary_key?_facet=a works correctly. |
I think I want "Forward all, cache based on all" for query strings, somewhere under "Cache behavior settings". |
That seemed to take effect pretty fast, https://d81numqdze872.cloudfront.net/fixtures/sortable?_facet=pk2 works now. |
I can't figure out how to enable the |
OK, I have that header now and it seems to confirm my 5s TTL is working as it should Next job: point a custom domain at https://d81numqdze872.cloudfront.net/ ! |
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html shows how to do that for HTTP (I'll add HTTPS later, following https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-https-alternate-domain-names.html ):
|
Now in my DNS provider:
|
Decided to click "Request certificate" and see what happens: Sent me to https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/request Looks like this has the validation bit: https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/98a4b28c-d7d1-4ad6-ae28-4db269e03ccc |
A few seconds later: Annoyingly that certificate is not shown in this drop-down menu: Maybe because this now says "Failed": https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/98a4b28c-d7d1-4ad6-ae28-4db269e03ccc |
I'm deleting the certificate and trying again. |
That came back "Failed" too. |
I'm going to try email validation. |
That deploy worked but it did not fix the bug - even though https://lambda-demo.datasette.io/-/plugins shows the new plugin. |
https://lambda-demo.datasette.io/-/asgi-scope seems to indicate that
|
https://aws.amazon.com/premiumsupport/knowledge-center/configure-cloudfront-to-forward-headers/ says:
|
That seemed to break everything: https://lambda-demo.datasette.io/ now returns:
|
Removing |
Definitely proven to myself that having |
I turned on a whole bunch of those extra headers: I tried to do even more but it gave me an error (tucked away at the bottom of the page where I initially missed it) complaining I had selected too many. Now https://lambda-demo.datasette.io/-/asgi-scope has this:
That latitude/longitude is on the edge of the small town where I live, so pretty accurate! |
These look relevant to my |
Aha! Here's a Twitter thread where someone notes that |
From this PR it looks like the answer may be to set |
Apparenty CloudFront Functions are NOT the same thing as Lambda@Edge: https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/ |
ARN is:
|
https://lambda-demo.datasette.io/ now says:
So it didn't like my new function. |
That fixed the error but https://lambda-demo.datasette.io/-/asgi-scope still shows no |
I switched it back to Viewer Request. |
I think this might be it: function handler(event) {
event.request.headers["x-forwarded-host"] = {
value: event.request.headers["host"].value
};
return event.request;
} Clue was here: https://www.honeybadger.io/blog/aws-cloudfront-functions/ That seems to work in the test mode: That worked!!
|
And now the "suggested facets" links on https://lambda-demo.datasette.io/fixtures/compound_three_primary_keys go to the right place. |
It looks like the homepage
Note the Other pages on the site with
|
[This issue thread provides a blow-by-blow account of how I figured out the way to serve an AWS Lambda function from a custom domain, using CloudFront and ACM]
I think Cloudfront is the way to do this:
My previous notes on how I shipped the Lambda Function URL are here: https://til.simonwillison.net/awslambda/asgi-mangum
The text was updated successfully, but these errors were encountered: