Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFront and API Gateway service on same domain

I want to:

  • Distribute the static part of the website (html, css, js) on my domain www.example.com.
  • Put API Gateway services on my domain under a folder, www.example.com/v1.

How do I accomplish this?

In route 53, from what I understand I can only point to one cloudfront distribution, so I am choosing my S3/CloudFront enabled bucket.

So, the end result should be, in order of priority/mapping:

  • www.example.com/v1/* <-> API Gateway <-> Lambda <-> DynamoDB
  • www.example.com/* <-> CloudFront <-> S3 bucket contents

In what way can I achieve this? And if not, what are my alternatives since I need to bend to the same origin principle requirement in web browsers.

like image 939
Wrench Avatar asked Mar 15 '17 19:03

Wrench


People also ask

Should I put CloudFront in front of API gateway?

Therefore, it's a best practice to place the CloudFront Distribution in front of the API Gateway and then enable protection on that distribution. Caching definitely could be a reason to use CloudFront with API Gateway.

Can CloudFront cache API gateway?

API gateway serves as the actual HTTP(s) based API. CloudFront, Fastly or any modern CDN can cache requests to that API.

Do you need Route53 with CloudFront?

Yes, it is possible to use a Cloudfront distribution using a registrar other than AWS without a Route53 public hosted zone. You don't need Cloudflare to do it. You can create an Alias record with the subdomain and target in your registrar's control panel. The target would be something like dabcxyz.cloudfront.net.

What is the difference between Route53 and CloudFront?

Both cloudfront and Route53 have different purpose. Route 53 is a DNS service whereas Cloudfront is CDN service to serve static (and dynamic) content. You can use the cloudfront with Route 53 Geolocation Routing .


1 Answers

You would setup CloudFront with two origins, S3 and API Gateway, and configure CloudFront to use the API Gateway origin for all requests that start with /v1

like image 68
Mark B Avatar answered Nov 14 '22 13:11

Mark B