I need to create a custom domain name for a websocket enabled API gateway and seems that CloudFormation for API gateway v2 (which is basically for websocket) doesn’t support it (at least the documentation https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-reference-apigatewayv2.html doesn’t mention this). I tried with AWS::ApiGateway::DomainName
which I believe is for Rest API gateway but the stack fails with the error
This custom domain name cannot map to WEBSOCKET protocol Apis.
I see that AWS CLI does support API gateway v2 create domain name command (https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/create-domain-name.html) but not sure the reason why the CloudFormation wouldn’t support this.
Any workaround or feedback would be greatly appreciated.
Usually the way it works is that new features first appear in CLI or APIs and are added to CFN later on. Why? Because I believe CFN uses the same API internally to create the resource with given properties. Here's a similar thread with same experience for when Aurora Serverless was released. Creating an Aurora serverless cluster from cloudformation
Workaround - create a lambda backed AWS::CloudFormation::CustomResource & call the createDomainName API from the lambda to create your custom domain name. Sometime in the future, it probably will be made available in cloudformation.
Update: No need for lambda custom resource. Better answer here