Hello everyone. Looking for some advice on this: -...
# help
l
Hello everyone. Looking for some advice on this: • I have one domain (ie: https://www.mydomain.com) and will have multiple SST frontend projects for separate business needs. • How can I have these multiple SST frontend projects distributed like that? ◦ https://www.mydomain.com/application1https://www.mydomain.com/application2https://www.mydomain.com/application3 Any ideas on how to accomplish that? Thanks in advance!
d
You are looking at a concept named “micro-frontends”. Googling that phrase should help. Warning: This is going to be much harder than you are probably thinking, and will likely be specific to your frontend choice (not SST).
From an infrastructure standpoint, Cloudfront has this capability, but your frontend choice will determine if that alone is enough.
l
If I could just import an existing distribution and add additional behavior, it would solve the issue, but it's NOT possible as their documentation suggests. So, I'm working with two workaround scenarios: 1. Continue having all these SST projects separate and SST will provision and deploy as usual, then having a shared CloudFront created manually on AWS so that I can just add a new distribution on the AWS console pointing to that s3 react site bucket deployment that SST just created. Pros: I won't need any complex or extra config on my SST. Cons: Have to manually create a new distribution for the shared CloudFront and keeping not used CloudFront and distribution automatically created for that app (any way to say to SST not creating these?) 2. Having a mono repo, then I first create a Distribution and add all the buckets internally created for all the apps contained in the monorepo. Pros: not needing to create anything manually on AWS. Cons: having the have all projects in a single repo
d
If you have simple sites with only S3, that makes it a little easier. • There is no reason for SST to be involved, really, and you will end up with [# of projects] meaningless cloudfronts and really slow deploys. SST only has single site constructs. • Either case you present is merely repo organization and the end product will look the same in AWS. That decision is totally up to you, either is possible and about the same difficulty. In either case, you will need to create the buckets and upload the sites FIRST, then create and hook the Cloudfront to them, though.
l
actually these SST projects may also contain simple lambdas, but for that it's easy to put behind
<https://api.mydomain.com/application1>
const api = new Api(stack, "Api") {
customDomain: {
path: "Application1",
cdk: {
domainName: CONFIGURE THE DOMAIN
}
}
}
the problem surfaces just for the web distributions that requires a different approach
f
@Leo Hick if u do decide to take the monorepo approach, ur app would probably look something like this:
Copy code
app
  .stack(Site1Stack)
  .stack(Site2Stack)
  .stack(Site3Stack)
  .stack(CloudFrontStack);
So in each of the Site stack, you can create a
sst.Bucket
to house the file; use the
BucketDeployment
construct to deploy ur files to the bucket (doc). Finally, in the CloudFront stack, you create a distribution and map the s3 origins.
As @Derek Kershner suggested, it’s probably not worth it to “hack” around and use
StaticSite
.
l
@Derek Kershner @Frank thank you for your insights!
a
@Frank this is what I was thinking to do too.
So we are going to have X stacks + 1.
And that means.. X CFronts + 1.
Each site will have their CFront and +1 with all the links.
d
I think you are misreading above. Should be 1 CFront.
a
The problem is…
Can I tell to
ReactStaticSite
to NOT create a CFront?
I need that construct to build my site, and etc.
I don’t want to build the app myself.
d
You can, definitely, do what you say, and I think it will probably work, but just was pointing out that would be against the above advice and would have significant downsides on complexity and cost.
a
Makes sense, yes.
Also found that a distribution can be
disabled
.
Maybe this can work, to disable all the other websites.
Well, I did a test but it didn’t work for me.
Basically did this…
Copy code
const assetWebsiteStack = new AssetsWebsiteStack(app, 'assetsWebsite-stack');
  const testWebsiteStack = new TestWebsiteStack(app, 'testWebsite-stack');

  new IssuerWebsiteStack(app, 'issuerWebsite-stack', {
    assetsWebsiteBucket: assetWebsiteStack.bucket,
    testWebsiteBucket: testWebsiteStack.bucket,
  });
Created 2 “react static site” and referenced the bucket from them.
Then my 3er stack, is the CFront with:
Copy code
additionalBehaviors: {
        'assets/*': {
          origin: new S3Origin(props.assetsWebsiteBucket),
        },
        'test/*': {
          origin: new S3Origin(props.testWebsiteBucket),
        },
      },
The bucket reference is coming from
ReactStaticSite
like
this.bucket = testWebsite.cdk.bucket;