# Using same custom domain URL for both API Gateway and S3 bucket

**URL:** <https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914>\
**Category:** Serverless Framework\
**Tags:** cloudformation, api-gateway\
**Created:** [March 26, 2020, 9:51pm UTC](https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914 "2020-03-26T21:51:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sc112233](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sc112233](https://forum.serverless.com/u/sc112233)\
**Post date:** [March 26, 2020, 9:51pm UTC](https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914/1 "2020-03-26T21:51:05Z")

</div>

Hi all-

I’m working on a SPA which will be hosted in an S3 bucket and works in conjunction with a few serverless lambdas. Ideally I would like to use the _same_ URL for both of these, for example:

[https://app.mydomain.com/api/\*](https://app.mydomain.com/api/*) -\> API Gateway / Lambda endpoints  
[https://app.mydomain.com/\*](https://app.mydomain.com/*) -\> S3 bucket index.html file

I’ve been able to set up a custom domain using my lambda using serverless-domain-manager for the lambda, and separately I’ve been able to set up a CloudFront Distribution for the S3 bucket, but I don’t see a way to create a single CF distribution that will point /api to API Gateway, and everything else to the S3 bucket.

An alternative approach would be something like:

[https://api.app.mydomain.com/api/\*](https://api.app.mydomain.com/api/*) -\> API Gateway / Lambda endpoints  
[https://app.mydomain.com/\*](https://app.mydomain.com/*) -\> S3 bucket index.html file

which would have 2 cloudfront distributions, one for the API, and one for the SPA. The downside of this is I need to configure CORS, which has been causing me headaches because I’m trying to use the default cognito authorizer on the API endpoints, and due to CORS issues I’m not getting the authorization errors returned to my app (I get CORS errors instead). There are other ways to solve that, but was hoping I could use the same URL and avoid doing that…

Any help would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![devinder-mt](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@devinder-mt](https://forum.serverless.com/u/devinder-mt)\
**Post date:** [June 16, 2020, 1:36pm UTC](https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914/2 "2020-06-16T13:36:11Z")

</div>

Hi , were you able to solve this ? I am stuck with same issue

---

<div class="post-metadata">

**Author:** ![sc112233](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@sc112233](https://forum.serverless.com/u/sc112233)\
**Post date:** [June 17, 2020, 8:24pm UTC](https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914/3 "2020-06-17T20:24:27Z")

</div>

No - I ended up implementing the “Alternative Approach” I described above - a separate domain for the API (which necessitated CORS…).

---

<div class="post-metadata">

**Author:** ![bozerkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bozerkins/32/6425_2.png) [@bozerkins](https://forum.serverless.com/u/bozerkins)\
**Post date:** [December 12, 2021, 11:09am UTC](https://forum.serverless.com/t/using-same-custom-domain-url-for-both-api-gateway-and-s3-bucket/10914/4 "2021-12-12T11:09:06Z")

</div>

I know it might be a little too late, but that can be done with AWS CloudFront.  
You can configure the routing rules there.
