Hi all! I'm looking for a best practice to deal wi...
# help
d
Hi all! I'm looking for a best practice to deal with custom domains (APIs and static sites) while having an AWS account per stage. So basically my
dev
and
prod
stages both have their own AWS account. Now, if I want my dev domain to be
<http://dev.domain.com|dev.domain.com>
and my prod domain to be
<http://www.domain.com|www.domain.com>
, what would be the best approach? From the guide:
Of course, you can change this if you’d like to use a custom domain for the other stages. You can use something like
${scope.stage}.<http://my-serverless-app.com|my-serverless-app.com>
. So for
dev
it’ll be
<http://dev.my-serverless-app.com|dev.my-serverless-app.com>
. But we’ll leave this as an exercise for you.
Should I just register the domain in the
prod
account and manually set the certificates for
dev
?
r
Hi Dimitri, I would use DNS delegation to delegate the subdomain
<http://dev.domain.com|dev.domain.com>
to the account use use for dev, that way the DNS and certificate creation can be handled automatically without any intervention. This should help you https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingNewSubdomain.html
Basically you are giving route53 in the dev account full control to manage the dns for the whole subdomain
<http://dev.domain.com|dev.domain.com>
so your SST/CDK code will just work on the existing a-count you are on.
d
Great, thanks!
r
d
Oops, I guess I just missed that chapter then 😳
f
Thanks @Rob N!
@Dimitri van Hees you can just stop after setting up the Route53 hosted zone in your dev AWS account. Skip the SEED steps.
The overall setup looks likes: 1. Ensure the
<http://domain.com|domain.com>
already exists in ur
prod
account 2. Follow the tutorial to setup
<http://dev.domain.com|dev.domain.com>
HostedZone in ur
dev
account 3. In SST app, set up Api domain:
Copy code
new Api(this, "api", {
  customDomain: scope.stage === "prod"
    ? "<http://api.domain.com|api.domain.com>"
    : `<http://api.dev.domain.com|api.dev.domain.com>`,
  ...
});
4. Setup StaticSite domain:
Copy code
new StaticSite(this, "site", {
  customDomain: scope.stage === "prod"
    ? "<http://www.domain.com|www.domain.com>"
    : `<http://dev.domain.com|dev.domain.com>`,
  ...
});
d
Hi @Frank, thanks, it works already 😉 Just missed the docs, my bad!