does anyone know how to attach multiple custom dom...
# help
s
does anyone know how to attach multiple custom domains to a single HTTP API?
it looks like `@aws-cdk/aws-apigateway`’s
DomainName
construct supports
mapping
, but `@aws-cdk/aws-apigatewayv2`’s
DomainName
does not. weird. is it ok to use the first one on an HTTP API?
f
what’s the setup like?
s
Copy code
this.restApi = new sst.Api(this, 'RestApi', {
  ...
  customDomain: { ... }
})
this supports only one custom domain
so I have to add a 2nd one after the fact.
f
what are the domains look like? Are they differnt paths of the same domain? Or two completely different domain?
s
api.reelcrafter.com & api2.reelcrafter.com. don’t ask 😆 it’s a strange edge case. basically if you point a CloudFront distribution to an HTTP API, you have to assign that CF CNAME to the API Gateway as well, so the Host header matches
so strange. you can create a domain name but can’t map it to anything? https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-apigatewayv2.DomainName.html
eh.. I’ll have to dig deeper into this one. I’ll post here if I find a solution
ah.. it’s
ApiMapping
I think. but I don’t know how to pass in the right object to the
api
property. it needs an
IApi
type. I really don’t understand CDK’s conventions
how do I get an
IApi
from an
HttpApi
?
f
What’s ur timeline on this? I think we can add support for this fairly quickly.
s
oh! that’d be super cool. I mean, I’m happy to just have a CDK-level workaround for now 🙂 we’re gonna have a rush of customers coming in soon.. probably just after Dec 31st
but no rush. I could do it later, too. it would just require maybe 5-10 mins of downtime as the domains change
f
actually, does a wildcard domain work for you in thihs case?
*.<http://reelcrafter.com|reelcrafter.com>
s
no, I don’t think so. the Host header has to be something specific
ok, so TypeScript doesn’t complain about any of this:
Copy code
const domain = new apigwv2.DomainName(this, 'Api2Domain', {
        domainName: '<http://api2.reelcrafter.com|api2.reelcrafter.com>',
        certificate: acmCert,
      });
      new apigwv2.ApiMapping(this, 'Api2Mapping', {
        api: this.restApi.httpApi,
        domainName: domain,
      });
I see in the docs this is experimental.. so it may not be a good idea to implement into SST?
@Frank I’m good! no need to rush on my part, but I really appreciate the thought 🙂 I found something that works. it’s a little verbose, but it’s not too bad
you just have to create a DomainName, an ApiMapping, and a route53.RecordSet, and plug in the appropriate values for all of those
but if
sst.Api
allowed for an array of custom domains, that certainly would be an awesome shortcut.
f
ah nice.. yeah, that’s what
Api
does behind the scene as well.
s
all of this is just an effort to speed up our API for our international customers. ultimately, the actual HTTP API will be something like
<http://regional-api.reelcrafter.com|regional-api.reelcrafter.com>
, and then the
<http://api.reelcrafter.com|api.reelcrafter.com>
“A” record will point to a CloudFront distribution that has
<http://regional-api.reelcrafter.com|regional-api.reelcrafter.com>
as an origin. and the API Gateway custom domain is needed so the Host header is what
<http://regional-api.reelcrafter.com|regional-api.reelcrafter.com>
expects
whew 😅
wow, all that work for zero impact on latency outside North America