I might be wrong but this piece of code from the <...
# help
b
I might be wrong but this piece of code from the documentation seems to not work as intended:
Copy code
import { StringParameter } from "aws-cdk-lib/aws-ssm";

const rootDomain = StringParameter.valueForStringParameter(this, `/myApp/domain`);

new ApiGatewayV1Api(this, "Api", {
  customDomain: {
    domainName: `api.${rootDomain}`,
    hostedZone: rootDomain,
  },
  routes: {
    "GET /notes": "src/list.main",
  },
});
I get this
Copy code
Error: Cannot determine scope for context provider hosted-zone.
This usually happens when one or more of the provider props have unresolved tokens
it works only when the
hostedZone
is a hardcoded string and not the value from ssm parameter store. my dev deps:
Copy code
"@serverless-stack/cli": "^1.1.0",
"@serverless-stack/resources": "^1.1.0",
"@tsconfig/node14": "^1.0.1",
"@types/aws-lambda": "^8.10.70",
"@types/node": "<15.0.0",
"aws-cdk-lib": "2.24.0"
f
Nice catch @Boris Tane. I can confirm the doc is wrong.
You’d have to hard code the hosted zone as CDK needs to verify the hosted zone exists at build time. But the SSM value is not resolved until build time.
Updated the doc.
Btw, just curious, what’s ur use case for storing domain names in SSM?
b
awesome, thanks 👍
I store domains in ssm as I have individual domains for different environments and that's the cheap and easy way I found to parametise it in the constructs. if you have any suggestions on a different way to do this, I'm all ears
also fyi in the piece of code from the docs, I managed to get it to work by building the hosted zone from parameters and passing it across. the type checker rejected it as it expects a string, but a good old //@ts-expect-error saved me. I'm not sure if you want people to be able to pass the hosted zone construct directly if they are unable to specify the domain explicitly as a string
s
@Boris Tane Could you please share the sample code for this (building the hosted zone from parameters and passing it across). I have also similar sitatuion
b
@Supriya N
Copy code
const hostedZoneId = ssm.StringParameter.valueForStringParameter(this, `hosted-zone-id`);

    // @ts-expect-error
    this.api = new sst.ApiGatewayV1Api(this, "api", {
      customDomain: {
        cdk: {
          domainName: apig.DomainName.fromDomainNameAttributes(this, "domain", {
            domainName: `${subDomain}.${domain}`,
            domainNameAliasTarget: "",
            domainNameAliasHostedZoneId: hostedZoneId,
          }),
        },
      },
    });