Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless HTTP API - serverless-domain-manager Error: Failed to find a stack

I'm trying to deploy the basic serverless express api example - https://github.com/serverless/examples/tree/v2/aws-node-express-api with a custom domain. It uses HTTP Api instead of the older REST API gateway. The domain has been set up successfully, certificate in place etc. but when I run serverless deploy it throws an error:

Error: Unable to setup base domain mappings for mycustom.domain.name

Adding SLS_DEBUG revealed:

Service Information
-------------------
service: my-service-name
stage: staging
region: us-east-1
stack: my-service-name-staging
resources: 11
api keys:
  None
endpoints:
  ANY - https://123323.execute-api.us-east-1.amazonaws.com
functions:
  api: my-service-name-staging-api
layers:
  None
Serverless: [AWS cloudformation 400 1.296s 0 retries] describeStackResource({
  LogicalResourceId: 'ApiGatewayRestApi',
  StackName: 'my-service-name-staging'
})
Serverless: [AWS cloudformation 200 1.592s 0 retries] describeStacks({})
Serverless Domain Manager: Error: mycustom.domain.name:  Error: Failed to find a stack my-service-name-staging

Serverless Domain Manager: Error: mycustom.domain.name:  Error: Failed to find CloudFormation resources for mycustom.domain.name

Clearly the stack exists, but serverless domain manager can't find it. Can I not use custom domain via serverless-domain-manager with HTTP api?? The documentation only shows a manual way to do this.. Any help would be greatly appreciated, thanks!

like image 675
kvnam Avatar asked Feb 14 '26 04:02

kvnam


2 Answers

It's hard to answer 100% without seeing your configuration, but are you sure you've specified apiType: http in your customDomain config section? If not, it defaults to rest. Setting it to http should resolve your problem.

like image 180
pgrzesik Avatar answered Feb 16 '26 20:02

pgrzesik


Since your complete serverless.yml is not here, I guess you are using the default one. I had the same issue, and here is my solution. This is probably the customDomain conf in your .yml file:

customDomain:
    domainName: sub.domain.com
    certificateName: '*.domain.com'
    basePath: ${sls:stage}
    stage: ${sls:stage} 
    createRoute53Record: true

The only thing you need to do is add these two attributes to convert your domain from edge to regional:

  customDomain:
    domainName: sub.domain.com
    certificateName: '*.domain.com'
    basePath: ${sls:stage}
    stage: ${sls:stage} 
    createRoute53Record: true
    endpointType: regional <-- New Attribute (default is edge)
    apiType: http <-- New Attribute (default is rest)

Remember, if you already have run the sls create_domain command (with the previous serverless.yml configuration), you might face this error:

Error:
Error: Unable to setup base domain mappings for 'sub.domain.com':
Unable to create base path mapping for 'sub.domain.com':
Only REGIONAL domain names can be managed through the API Gateway V2 API. For EDGE domain names, please use the API Gateway V1 API. Also note that only REST APIs can be attached to EDGE domain names.

The reason for this error is that you have created an edge domain with the previous configuration, and now, the deployment wants to use it as a regional domain. To solve this error, just delete the domain with sls delete_domain and then rerun the sls create_domain command. I will automatically create the new records for you.

like image 35
Leo Avatar answered Feb 16 '26 20:02

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!