Custom Domain Name for WebSockets API with Serverless


I’m managing a REST API for an app with Serverless and want to extend this setup with a WebSockets API in the same region. Everything should be handled with the same certificate, but different subdomains.

At first I created a new custom domain with sls create_domain --stage=....
Then I tried to add it to the new WebSockets stack, but ended with this error:

Error: Failed to find CloudFormation resources for …

I found it on Github that this seems to be not supported by CloudFormation right now so Serverless does not support it.

So I tried to attach my stage to the custom domain name manually in the UI:

Mixing of REST APIs and HTTP APIs on the same domain name can only be
accomplished through API Gateway’s V2 DomainName interface. Currently,
WebSocket APIs can only be attached to a domain name with other
WebSocket APIs. This must also occur through API Gateway’s V2
DomainName interface.

More confusion arises, as it’s not even the same domain name in this case. The new domain name was sockets.<DOMAIN>.com and the existing one was api.<DOMAIN>.com. Or do different subdomains are falling into ‘same domain name’?

Nevertheless I tried to create the custom domain again via the apigatewayv2 CLI:



But this results in the following error:

An error occurred (BadRequestException) when calling the CreateDomainName operation: Invalid certificate ARN: arn:aws:acm:us-east-1:924441585974:certificate/b88f0a3f-1393-4a16-a876-9830852b5207. Certificate must be in ‘eu-west-1’.

My current state was that API Gateway only allows custom certificates to be located in us-east-1, so this error confuses me even more.

Summary: I’m completely stuck on how to get a custom domain name attached to my WebSocket API stage. I’m happy about every hint in the right direction!


Found a solution with a custom CloudFormation resource template:

Edit: Now working with serverless-domain-manager! 🎉

Leave a Reply