- Newest
- Most votes
- Most comments
Are you specifying your api origin as an ALB or as an HTTP/S server? If the former (which I think is correct) then wouldn't the constructed origin URL be based on the default ALB domain not your CNAME?
I have the exact same behaviour but wasn't able to get it to work. Did you have any luck?
The steps provided in the documentation links below are summarized as follows:
- Open the CloudFront distribution settings in the AWS Management Console.
- Go to the "Behaviors" tab and click "Create Behavior" to create a new custom behavior.
- For "Path Pattern," enter /api/* to match all requests that start with /api/.
- For "Cache Policy," select "CachingDisabled".
- For "Origin Request Policy," select "AllViewer" to forward the request to the origin (ALB).
- Configure the origin settings for the ALB:
- Origin Domain Name: the domain name or endpoint of your ALB.
- Origin Path: /api/v1.
Save the behavior and wait for the CloudFront distribution to update. Ensure you did this correctly. It might take some time for CloudFront to update.
If this is what you did and you still are facing origin path problems, follow the more detailed AWS instructions for your CloudFront multi-origin setup: https://catalog.us-east-1.prod.workshops.aws/workshops/4557215e-2a5c-4522-a69b-8d058aba088c/en-US/basic-configuration/create-multiple-origins
Values you want to put in when configuring with CloudFront: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html
Hope these resources help!
Relevant content
- asked 3 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 9 months ago
I specify the API origin as an HTTPS server. If I use the ALB from the drop-down list, Cloudfront tries to connect to the ALB FQDN over HTTPS and fails because the TLS cert is only valid for the CNAME (service.example.com) and not
*.elb.aws.amazon.com
.So, I have a domain name, say,
api-alb.example.com
pointing to the ALB (ALIAS-A rec on Route53) and the origin is set toapi-alb.example.com
over HTTPS. This ensures that the certificate configured at the ALB is valid for the FQDN to which Cloudfront is trying to connect.