Last active
April 9, 2024 15:02
-
-
Save fwang/db1e5697913c5533f8b95a4f04464870 to your computer and use it in GitHub Desktop.
Demonstrate how to get around of circular dependencies in SST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Lazy } from "aws-cdk-lib"; | |
import * as sst from "@serverless-stack/resources"; | |
export class MainStack extends sst.Stack { | |
constructor(scope: sst.App, id: string) { | |
super(scope, id); | |
let site; | |
// Create Api | |
const api = new sst.Api(this, "Api", { | |
defaultFunctionProps: { | |
environment: { | |
// Instead of evaluating `site.url` in place which is undefined at the moment, | |
// Lazy value evaluates it after `site` is defined. | |
// More details here - https://docs.aws.amazon.com/cdk/v2/guide/tokens.html#tokens_lazy | |
SITE_URL: Lazy.stringValue({ | |
produce(context) { | |
return site.url; | |
} | |
}) | |
}, | |
}, | |
routes: { | |
"GET /": "src/lambda.main", | |
}, | |
}); | |
// Create StaticSite | |
site = new sst.StaticSite(this, "Frontend", { | |
path: "src/sites/website", | |
environment: { | |
API_URL: api.url, | |
}, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment