7
votes

I want to setup a custom domain with the serverless framework and AWS.

This is what I have in serverless.yml

service: chapiLabs-rest-api

plugins:
  - serverless-domain-manager
  - serverless-express

custom:
  customDomain:
    domainName: chapitime.chapilabs.com
    basePath: ''
    stage: ${self:provider.stage}
    certificateName: '*.chapilabs.com'
    createRoute53Record: true

package:
  exclude:
    - node_modules
  include:
    - dist

provider:
  name: aws
  runtime: nodejs8.10

webpackIncludeModules:
  forceInclude:
    - mysql
    - mysql2
    - sequelize

functions:
  get:
    handler: dist/get.get
    events:
      - http:
          path: v1/client/{id}
          method: get
          request:
            parameters:
              paths:
                id: true
  create:
    handler: dist/auth.auth
    events:
      - http:
          path: v1/auth
          method: post

I used this npm package as plugin: https://github.com/amplify-education/serverless-domain-manager

I added a certificate via DNS using CloudFlare

enter image description here

Then I made a deploy and got the next log.

enter image description here

In cloudflare I added a CNAME to add the ACM validation and another CNAME pointing cloudfront.

enter image description here

But the domain name is not working. Any ideas why? I didn't bought the domain in AWS.

1
How have you configured this domain in CloudFlare?Michael - sqlbot
I edited my question to add the cloudflare infofcpauldiaz
Observing your configurarion using dig, it looks like something has changed since you added the cloudflare configuration. Your DNS record now points to a different Distribution Domain Name than the one shown here, d33gyq....cloudfront.net and it appears to be working. What changed?Michael - sqlbot
For some reason the cloudfront url changed and I didn't noticed before making this question. I changed and it started working. So now I just hope the cloudfront url doesn't change after deployments.fcpauldiaz

1 Answers

5
votes

After some deployments the cloudfront url changed and I didn't noticed. I just updated the CNAME record in CloudFlare and it started working.