I'm using the StaticSite construct for my domain w...
# help
w
I'm using the StaticSite construct for my domain which isn't on Route 53. After deployment I can configure the distribution manually (via the console) with an ACM certificate and "Alternate domain name (CNAME) - optional"; all works fine until the next redeployment. If I set these in SST via config.cfDistribution then I get fatal errors "Do not configure the cfDistribution.domainNames ...."  and "Do not configure the "cfDistribution.certificate ..." "... use the customDomain ...".  However, the documentation says that customDomain is only for Route53 domains. Should those fatal errors be just warnings if the customDomain property is not specified? Or is there another solution I'm missing?
t
Interesting - I think StaticSite might not support this exact use case. @Frank what was the thinking behind disallowing people from specifying their own certificate? To nudge them to customDomain if they didn't know it existed?
f
hmm.. you should be able to provide ur own certificate like this:
Copy code
import { Certificate } from "@aws-cdk/aws-certificatemanager";

new StaticSite(this, "Site", {
  path: "path/to/src",
  customDomain: {
    domainName: "<http://domain.com|domain.com>",
    certificate: Certificate.fromCertificateArn(this, "MyCert", certArn),
  },
});
@Warwick Grigg u mentioned the domain is not purchased on Route53. is the DNS managed by Route 53? ie. do you have a Hosted Zone in ur Route 53 console with the domain name?
w
@Frank the DNS is managed outside Route 53. I created CNAME records there (which I need do once only). I created an ACM certificate and validated it manually (which I need do once only). That all works fine if I enter the CNAMES and cert directly in the distribution via the web console. Of course the next deployment removes those settings, so I just want to automate the deployment for the CNAMES and cert. I get the certificate for the cfDistribution prop via Certificate.fromCertificateArn(this, "MyCert", certArn) (just like the docs for customDomain). I've looked at the code and I think all code changes would be within createCfDistribution in packages/resources/src/StaticSite.ts . My naïve thoughts are 1) Wrap validation with if (customDomain) {...} 2) build return values for domainNames and certificate from customDomain if customDomain is specified otherwise from cfDistribution.
f
Got it! Yeah, that should be a quick change to
StaticSite
to support non-Route 53 domain.
For now, can you give this a quick try: 1. Create a dummy Route 53 hosted zone with the name of ur domain 2. Configure the
customDomain
in
StaticSite
pretending the domain is hosted on Route53
Copy code
customDomain: {
    domainName: "<http://domain.com|domain.com>",
    certificate: Certificate.fromCertificateArn(this, "MyCert", certArn),
  },
This should actually work.
w
@Frank I get this error thrown: "It seems you are configuring custom domains for you URL. And SST is not able to find the hosted zone "domain.com;" in your AWS Route 53 account. Please double check and make sure the zone exists, or pass in a different zone."
f
Yeah, you have to create a Hosted Zone in your Route 53 console with your domain.
(you can remove this after StaticSite supports non-Route 53 domains)
w
@Frank ... by the way my website domain is a subdomain.domain.com
f
Oh i see.. create the hosted zone for “subdomain.domain.com
w
@Frank Yes, that works. Thank you. If I were to create a PR for the changes I outlined, I'm sure I could write conformant quality code, but what else would be involved for tooling, testing etc? Is there a beginner's guide for that?
f
That’d be awesome! Here’s a link to the contributing guide, the relevant part might be: 1. Clone the repo 2. Working on resources 3. Submitting a PR
And yeah, let’s add some tests for this use case.
w
OK I'll give that a try
@Frank I followed the guide (but first I installed yarn, npm install -g yarn) but I've hit a snag: on yarn test test/StaticSite.test.ts, I get "Cannot find module '@serverless-stack/core' from 'src/util/permission.ts'". I haven't made any changes yet. I can see @serverless-stack/core is a dependency in package.json but I'm naively assuming that lerna should have handled that? I've never used yarn before nor lerna.
f
Hey @Warwick Grigg, can you try running
yarn
at the root of the repo. That will ensure all the local packages are hooked up.
w
Hi @Frank Yes I did that. I've done it again and get the same result. Here's the details:
$ yarn yarn install v1.22.11 [1/4] Resolving packages... success Already up-to-date. $ lerna run prepare --scope='{@serverless-stack/resources,@serverless-stack/cli,create-serverless-stack}' lerna notice cli v3.22.1 lerna notice filter including "{@serverless-stack/resources,@serverless-stack/cli,create-serverless-stack}" lerna info filter [ lerna info filter '{@serverless-stack/resources,@serverless-stack/cli,create-serverless-stack}' lerna info filter ] lerna info Executing command in 3 packages: "yarn run prepare" lerna info run Ran npm script 'prepare' in 'create-serverless-stack' in 0.4s: yarn run v1.22.11 $ node ./bin/get-cdk-version.js Syncing with aws-cdk version 1.111.0 Done in 0.13s. lerna info run Ran npm script 'prepare' in '@serverless-stack/resources' in 6.3s: yarn run v1.22.11 $ node ./bin/aws-cdk-version-check.js && npm run build AWS CDK versions in @serverless-stack/resources is in sync with @serverless-stack/core
@serverless-stack/resources@0.37.2 build
tsc --rootDir src --outDir dist && cd assets/stub && yarn && cd ../.. && node ./bin/create-stub-zip.js
[1/4] Resolving packages... success Already up-to-date. Stub Lambda is successfully created. Done in 6.08s. lerna info run Ran npm script 'prepare' in '@serverless-stack/cli' in 0.3s: yarn run v1.22.11 $ node ./bin/sync-cdk-version.js AWS CDK packages in @serverless-stack/cli are in sync with @serverless-stack/core Done in 0.18s. lerna success run Ran npm script 'prepare' in 3 packages in 6.7s: lerna success - @serverless-stack/cli lerna success - create-serverless-stack lerna success - @serverless-stack/resources Done in 8.47s.
and yarn test test/StaticSite.test.ts yarn run v1.22.11 $ jest test/StaticSite.test.ts FAIL test/StaticSite.test.ts ● Test suite failed to run Cannot find module '@serverless-stack/core' from 'src/util/permission.ts' Require stack: src/util/permission.ts src/Function.ts src/Api.ts src/index.ts test/StaticSite.test.ts 3 | import * as cdk from "@aws-cdk/core"; 4 | import * as iam from "@aws-cdk/aws-iam"; > 5 | import { getChildLogger } from "@serverless-stack/core"; | ^ 6 | import { 7 | Api, 8 | Table, at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js30611) at Object.<anonymous> (src/util/permission.ts51) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.579 s Ran all test suites matching /test\/StaticSite.test.ts/i. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
f
hmm.. lemme give it a try on a fresh clone
it worked for me.. let me pull in @Jay and see if he can spot anything
@Jay Warwick is working on a PR, and is having some trouble running the resources test
From the error, it seems importing
@serverless-stack/core
is failing within
@serverless-stack/resources
j
Hmm that is weird. This should be handled with Lerna and Yarn. @Warwick Grigg do you mind sharing your OS and Node versions?
w
@Jay Of course. Ubuntu 20.04.2 LTS (within WSL2), node v14.15.1 (via nvm v0.37.2). Normally I'm using npm v7.7.3. I'm using yarn and lerna for the first time.
j
Thanks. @thdxr have you seen something like this in your Linux setup?
t
I didn't run into any issues. I am curious, can you
ls -lah node_modules/@serverless-stack/
Those should all be symlinks
I'm on node16 btw
j
I’m on Node 12 but on OSX.
t
Also would like to see output of
ls -lah ./packages/resources/node_modules
w
@thdxr 1. all symlinks to ../../packages/..., , eg. core -> ../../packages/core 2. drwxr-xr-x 2 warwick warwick 4.0K Aug 10 09:13 .bin drwxr-xr-x 3 warwick warwick 4.0K Aug 10 08:31 fs-extra drwxr-xr-x 2 warwick warwick 4.0K Aug 10 08:31 glob drwxr-xr-x 2 warwick warwick 4.0K Aug 10 08:31 jsonfile drwxr-xr-x 2 warwick warwick 4.0K Aug 10 08:31 universalify
t
Can you try running
yarn build
In core
I think we need to add core to
postinstall
of the root package.json
@Warwick Grigg I'm merging a PR that should fix your issue. Additionally we made it so you can run
yarn watch
in the root and it'll run a watcher across the projects in the monorepo that use TS
w
@thdxr Thank you, yes the the test runs properly after
yarn build
in core
@Frank I've submitted a new PR which includes updated documentation.
f
Thanks @Warwick Grigg, will take a look at it today!