amplify-education / serverless-domain-manager

Serverless plugin for managing custom domains with API Gateways.
MIT License
941 stars 232 forks source link

How to deploy a custom domain created in other region? #497

Closed sleiter88 closed 1 year ago

sleiter88 commented 2 years ago

Community Note

Support Question

Question I have all my serverless services in eu-west-1 but I need to migrate one service to us-west-1 so i remove it from eu-west-1 and then I try to deploy it in the new region but I receive the following error: TypeError: Cannot read property 'domainName' of undefined so i suppose the new region needs a "create_domain" command to configure it in that region. But when I execute the "create_domain" command I receive the following error: Error: Error: Unable to create domain myapi.domain.com so I thinks is about the domain already exists in other region but I don't know how to use it in us-west-1

Domain Manager Configuration Replace this with your own serverless.yml file (anonymized, of course) to help us better resolve your issue.

customDomain:
    domainName: ${self:custom.domain.${opt:stage}}
    basePath: ${self:service}
    stage: ${self:custom.stage}
    createRoute53Record: true
    route53Params:
      routingPolicy: latency

Versions

ajmichels commented 2 years ago

It looks like if you want to used a specific region for your certificate you need to use endpointType: 'regional'. This is because the default edge endpoint type uses a CloudFront distribution which can only support certificates for the us-east-1 region.

So by specifying the 'regional' endpoint type this plugin will assume your certificate is within the region specified in provider.region in your serverless.yml file. Obviously you will want to make sure that the regional endpoint type is appropriate for your needs. In my case I am not expecting any API traffic from outside of that region so it will work just fine. But if you are expecting global traffic to your API you will want to stick with edge and create your cert in the us-east-1 region. It is kind of a pain, but it is an AWS limitation not a Serverless or serverless-domain-manager limitation. If you want to use CloudFront for anything else you are going to run into the same limitation.

rddimon commented 1 year ago

Hi @sleiter88

Hope you have solved this issue. It looks like you have a solution in the comment above.

Also, we are not supporting 4.x anymore please try our latest version 6.x and let us know in case of any issues