# Custom domain name for both cloudfront and lambda?

**URL:** <https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002>\
**Category:** Serverless Framework\
**Created:** [November 1, 2017, 8:15am UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002 "2017-11-01T08:15:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ObiWan](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@ObiWan](https://forum.serverless.com/u/ObiWan)\
**Post date:** [November 1, 2017, 8:15am UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/1 "2017-11-01T08:15:54Z")

</div>

Hi.

Im setting up an application in aws and I have added a custom domain name for my lambda functions. Im from a spring boot world and my first thought was that if I run a solution on [www.mydomain.com](http://www.mydomain.com) then my website should be reached by [www.mydomain.com](http://www.mydomain.com) and my api gateway should use [www.mydomain.com/apii](http://www.mydomain.com/apii). But when I try to distribute my webpage with cloudfront Im not allowed to use the custom domain name since its already used for my api gateway.

Am I just doing it wrong or should I think differently. I mean should my cloudfront and lambda run on different custom domains? but then Ill have to allow cors right?

Looking forward to hear from you guys.

Best regards.  
Obiwan =)

---

<div class="post-metadata">

**Author:** ![ObiWan](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@ObiWan](https://forum.serverless.com/u/ObiWan)\
**Post date:** [November 1, 2017, 9:29am UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/2 "2017-11-01T09:29:15Z")

</div>

I found a nice guide for this

> **[Processing A Contact Form Using AWS Cloudfront, API Gateway, Lambda and SES](https://www.codeengine.com/articles/process-form-aws-api-gateway-lambda/)**
>
> Example Of Processing A Contact Form With AWS Cloudfront, API Gateway, Lambda and SES (Amazon Web Services)

In case somebody else needs it =)

But there is alot of configuration to do here in cloudfront. I hope somehow I can copy that when I want to move from dev to production.

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [November 6, 2017, 8:41pm UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/3 "2017-11-06T20:41:22Z")

</div>

You should be doing your CloudFront configuration in CloudFormation.

You can do CloudFormation in your `serverless.yml` (under the `resources` property), but I probably wouldn’t do it in the _same_ `serverless.yml` as your application - Your CloudFront distribution will rarely change, so it’s best to keep it separate (i.e. in a resource-only service).

---

<div class="post-metadata">

**Author:** ![ObiWan](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@ObiWan](https://forum.serverless.com/u/ObiWan)\
**Post date:** [November 8, 2017, 8:25pm UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/4 "2017-11-08T20:25:52Z")

</div>

Thx for the answer rowanu. Ill look into cloudformation.

Regarding my original question I found out that I dont really need a domain pointing to my apigateway. I used serverless.yml files to configure the api. But the downside of this is that all my functions got their own tiny api’s. I have moved away from that and now I just use serverless to upload the function. Then I setup the api manually in the aws console. That way all the functions can be under one common api and the basic url doesnt change. That way I can have a dev url and a prod url in my frontend and I dont have to update it all the time.

---

<div class="post-metadata">

**Author:** ![tommedema](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tommedema/32/1257_2.png) [@tommedema](https://forum.serverless.com/u/tommedema)\
**Post date:** [November 12, 2017, 10:34am UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/5 "2017-11-12T10:34:28Z")

</div>

@ObiWan it seems like bad practice to manually click around Amazon’s GUIs. You should really manage your infrastructure from cloudformation, probably within serverless.yml. Otherwise it would be hard for other developers to work on your infrastructure, and it would be hard to run automated tests in your continuous integration pipelines (as they cannot easily spawn a new instance of your setup).

---

<div class="post-metadata">

**Author:** ![ObiWan](https://avatars.discourse-cdn.com/v4/letter/o/e47774/32.png) [@ObiWan](https://forum.serverless.com/u/ObiWan)\
**Post date:** [November 12, 2017, 6:42pm UTC](https://forum.serverless.com/t/custom-domain-name-for-both-cloudfront-and-lambda/3002/6 "2017-11-12T18:42:50Z")

</div>

I completely agree. But if I create all my functions in one serverless project, wont I get one big “function” which will take longer time to “wake” from hibernation when it runs? I have splittet all my functions into different projects and that means that I get an api for each if I configure it in the projects. Am I with serverless able to configure the apis for functions which is not in the current project. If so that would be neat, then I could have an api project and still have lots of small functions.
