question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-cloudfront] cloudfront won't forward request to custom domain HTTP API.

See original GitHub issue

❓ General Issue

The Question

I am serving static website with S3/Cloudfront at / and I have set custom domain HTTP API at /api/* as per CDK documentation on apigatewayv2 but cloudfront won’t forward request to HTTP API. Cloudfront will serve 404 not found to any /api/* path.

Environment

  • CDK CLI Version:
  • Module Version:
  • Node.js Version:
  • OS:
  • Language (Version):

Other information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ffxsamcommented, Dec 22, 2021

Solved! For anyone else looking for the solution:

new cloudfront.Distribution(this, 'Dist', {
  defaultBehavior: {
    origin: new origins.HttpOrigin(
      core.Fn.select(1, core.Fn.split('://', httpApi.url))
    ),
  },
});
0reactions
ffxsamcommented, Dec 22, 2021

This is still an issue. What’s the proper way to set up an HTTP origin in CDK? @rix0rrr @njlynch

I see in a post above, you said to use the API endpoint, but that doesn’t work either:

new cloudfront.Distribution(this, 'Dist', {
  defaultBehavior: {
    origin: new origins.HttpOrigin(httpApi.apiEndpoint),
  },
});

The end goal is to set up a CF distribution with a CNAME alias (like api.mydomain.net) and have the origin be a “raw” HTTP API endpoint (*.execute-api.us-east-1.amazonaws.com).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set up API Gateway with a custom CloudFront distribution
I want an edge-optimized API endpoint in Amazon API Gateway, but I need more control over the Amazon CloudFront distribution.
Read more >
How to forward cloudfront to HTTP API with custom domain
Basically Cloudfront is not forwarding my /api/* request to the HTTP API. Here is my cloudfront CDK code const distribution = new ...
Read more >
CloudFront wrapped API Gateway but don't pass HOST Header?
tl/dr: Origin Request Policy ALL_VIEWER on CloudFront lets Header Host ... Custom Domains on API Gateway won't solve the problem (HOST still ...
Read more >
Prevent requests from accessing API directly
With Amazon CloudFront, you can also enforce encrypted end-to-end ... 3.2 Add custom HTTP headers to the requests. ... Section3 CloudFront Domain Name....
Read more >
Customize your Portal's domain with CloudFront and Route53
To configure your Portal to make it work on SSL you can use AWS Cloudfront which is a CDN that allows you to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found