Reputation: 1455
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!
Upvotes: 2
Views: 5211
Reputation: 361
I'm using Python wsgi app and in my case, this solved the issue:
custom:
wsgi:
app: api.app
customDomain:
basePath: ${opt:stage}
domainName: mydomain.name.com
stage: ${opt:stage}
createRoute53Record: true
createRoute53IPv6Record: true
endpointType: 'regional'
securityPolicy: tls_1_2
autoDomain: true
without specifying http:
source: https://www.serverless.com/plugins/serverless-wsgi
Upvotes: 0
Reputation: 912
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.
Upvotes: 2
Reputation: 2427
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.
Upvotes: 3