Search code examples
aws-api-gatewayamazon-cloudfront

Creating API on same domain used by AWS CloudFront


I have a React website being served by AWS CloudFront and S3. I want a contact me section which sends details to an API using API gateway and Lambda.

Is it possible to setup the API endpoint to be on the same domain used by cloudfront?

For example:

POST www.example.com/contact-us --> API gateway --> Lambda
www.example.com/* --> Cloudfront --> S3

Solution

  • Edge optimized API gateway also use CloudFront basically and you can't have same domain name with CloudFront and API gateway but you could define API gateway as an origin of CloudFront and cache behaviour with path e.g: /contact-us and can trigger API gateway, if not, you could write js to trigger the API GW endpoint (aws dns name) directly from contact-us page.