How to use multi custom domains for aws serverles project?

674 views Asked by At

Is it possible to have lambda function with different custom domain than others; In servlerless lambda project, I need to have one lambda to use different custom domain than other lambdas. for example userNotification --> dev.xyz.com/users all others getProducts --> dev.abc.com/products I tried using custom domain as following but it did not work.

        userNotification:
            handler: src/index.handler
            events:
              - http:
                  method: get
                  path: /userNotification
                  cors:
                    origin: '*'
                    headers:
                      - Content-Type
                      - X-Amz-Date
                      - Authorization
                      - X-Api-Key
                      - X-Amz-Security-Token
                      - If-Match
                      - If-None-Match
            # override default customDomain
            customDomain:
              domainName: 'dev.xyz-comm-sanbox.com'
              basePath: dev-newbank
              stage: dev
              createRoute53Record: true
    

In serverless.yml, I'm using custom domains as, this work fine but then i have single customDomains for all lambdas funcrion. I need to have one lambda to use different customDomain than others;

           custom:
             customDomain:
               basePath: dev-newbank
               domainName: 'dev.abc.com'
               stage: 'dev'
               createRoute53Record: true
               endpointType: regional
               securityPolicy: tls_1_2
2

There are 2 answers

1
Brian Winant On

I think you would have to have 2 different serverless.ymls, 1 for managing your /products path and one for /users. Then you could specify different domains for each. Since underneath it all API Gateway only supports custom domains on the API, not on individual endpoints in the API, you would have to split your lambdas up

0
user21684843 On

I think so you can also use both the domains in one custom domain instead of 2.

For Ex: customDomain: domainName: 'dev.xyz-comm-sanbox.com' basePath: dev-newbank stage: dev createRoute53Record: true customDomain: basePath: dev-newbank domainName: 'dev.abc.com' stage: 'dev' createRoute53Record: true endpointType: regional securityPolicy: tls_1_2