amplify-education / serverless-domain-manager

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

Api Gateway V2 (httpApi) not working with non-Route53 domain. #517

Open yasso1am opened 2 years ago

yasso1am commented 2 years ago

Community Note

Bug Report

I am unable to receive a Cloudfront distribution link through the process of running sls create_domain and sls deploy.

I am attempting to deploy an Api Gateway V2, as in an http api. From my reading, it appears I can only do this with regional endpoint types, since edge-optimized are not supported. I created my certificate in the correct region, and validated successfully through DNS validation. I am NOT using Route53, but instead using Cloudflare. As such, I have set createRoute53Record to false.

Command Run sls create_domain --verbose

sls deploy

Console Output

sls create_domain --verbose
Running "serverless" from node_modules
'dev.domain.com' does not exist.
Searching for a certificate with the 'dev.domain.com' domain
Custom domain 'dev.domain.com' was created.
                 New domains may take up to 40 minutes to be initialized.
Creating/updating route53 record for 'dev.domain.com'.
Skipping creation of Route53 record.

meaningful output from sls deploy

Serverless Domain Manager:
 Domain Name: dev.domain.com
 Target Domain: d-randomId.execute-api.us-west-2.amazonaws.com
 Hosted Zone Id: Z2OJLYMUO9EFXC

Notice the target domain is just to my api gateway, instead of a cloudfront distribution.

Domain Manager Configuration

custom:
  customDomain:
    domainName: dev.domain.com
    basePath: api
    apiType: http
    createRoute53Record: false
    endpointType: regional
    autoDomain: true
    securityPolicy: tls_1_2

Versions

Possible Solution When I remove all of my http lambdas and instead deploy as a REST api (api gateway v1), as well as recreate my certificate in us-east-1 for an edge-optimized endpoint, and update my config to remove any mention of the apiType or endpointType, I can create the domain as well as deploy and I receive a Cloudfront distribution link no problem. I just don't know why it won't work with httpApi.

Thanks for any help in advance!

miguel-flowalytics commented 1 year ago

I have the same setup using cloudflare, but I'm getting an error

service-5 › error
service-5 › Error:
service-5 › Error: Unable to setup base domain mappings for 'staging-api.domain.com':
service-5 › Failed to find CloudFormation resources for 'staging-api.domain.com':
service-5 › Failed to find a stack service-5-staging
service-5 › 
service-5 ›     at ServerlessCustomDomain.<anonymous> (/Users/hello/Code/project/project-serverless/services/service-5/node_modules/serverless-domain-manager/dist/src/index.js:294:27)
service-5 ›     at Generator.throw (<anonymous>)
service-5 ›     at rejected (/Users/hello/Code/project/project-serverless/services/service-5/node_modules/serverless-domain-manager/dist/src/index.js:6:65)
service-5 ›     at processTicksAndRejections (node:internal/process/task_queues:96:5)
service-5 › 

Heres my configuration:

  customDomain:
    domainName: ${self:custom.domain} # staging-api.domain.com
    stage: ${self:custom.currentStage}    # staging
    certificateName: '*.domain.com'
    basePath: 'products'
    endpointType: regional
    apiType: http
    securityPolicy: tls_1_2
    autoDomain: true
    createRoute53Record: false

The stack for the service exists, so unsure what could be the issue here. Could it be the certificate name with the wildcard?

light320180 commented 1 year ago

I also encountered a similar error: (Tried the latest version, same error)

Environment: win32, node 14.18.0, framework 3.27.0 (local) 3.19.0v (global), plugin 6.2.3, SDK 4.3.2
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: Failed to find a stack polling-api-lightxie
    at CloudFormationWrapper.<anonymous> (E:\workspace\dev\polling\backend\node_modules\serverless-domain-manager\dist\src\aws\cloud-formation-wrapper.js:97:23)
    at Generator.next (<anonymous>)
    at fulfilled (E:\workspace\dev\polling\backend\node_modules\serverless-domain-manager\dist\src\aws\cloud-formation-wrapper.js:8:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Heres my configuration:

customDomain:
  domainName: ${self:custom.stageDomain.${self:provider.stage}, self:custom.stageDomain.other}
  certificateName: ${self:custom.stageCert.${self:provider.stage}, self:custom.stageCert.other}
  basePath: polling
  stage: ${self:provider.stage}
  endpointType: regional
  apiType: http
  createRoute53Record: true
  securityPolicy: tls_1_2

@rddimon If you have a chance, please take a look, thank you.

ctrlsam commented 1 year ago

Same issue with my configuration:

custom:
  customDomain:
    domainName: api.staging.domain.com
    certificateArn: arn:aws:acm:us-east-1:<redacted>:certificate/<redacted>
    createRoute53Record: false
    autoDomain: true
    apiType: http
    endpointType: regional
    basePath: ""

Output

...
Serverless Domain Manager:
  Domain Name: api.staging.domain.com
  Target Domain: d-<redacted>.execute-api.us-east-1.amazonaws.com
  Hosted Zone Id: <redacted>

Versions

Domain Manager version(s): ^7.1.2
Node/npm version: Node v18.17.1/NPM 9.8.1
Serverless Version: ^3.33.0
Lambda Code: Typescript

And upon navigating to the domain, it does not resolve. I have given sufficient time for DNS settings to propagate.

dario1985 commented 1 year ago

I solved removing the domain with sls delete_domain, and recreate it with this configuration:

custom:
  customDomain:
    domainName: <mydomainname>
    createRoute53Record: true
    apiType: http <----
    endpointType: REGIONAL <----
    securityPolicy: tls_1_2

and then doing the deploy.