https://serverless-stack.com/ logo
#help
Title
# help
d

Devin

02/11/2022, 11:14 PM
I'm going to remove a stack hosted at my
<http://domain.com|domain.com>
on route 53 and move it to... Netlify I guess. I'll keep
<http://app.domain.com|app.domain.com>
for the SST application. Effectively splitting the static site and the application. Anyone have any thoughts about things I should watch out for?
t

thdxr

02/11/2022, 11:14 PM
curious what pushed you to do this?
I went the other way because splitting my environments, variables, etc wasn't worth it
d

Devin

02/11/2022, 11:15 PM
There's no way to host a static page on CDK that I can make work.
Either I'm doing it wrong or having static html isn't really doable. https://github.com/serverless-stack/serverless-stack
j

Jason Melis

02/12/2022, 1:56 PM
@Devin are you looking to do something like this or something different? https://medium.com/swlh/host-a-static-website-on-s3-using-aws-cdk-b9151213aad4
d

Devin

02/12/2022, 3:06 PM
Yes I am. I've tried that but it didn't work. I'll give it another go this morning. Maybe I missed something
I’m trying this and have tried a few other configurations. I’m pretty conviced CDK is great for anything but static websites. If it’s a single page app, go for it. But at this point, it’s not obvious what’s wrong and there’s no real clarity on how to fix it. Even
<http://thecdkbook.com|thecdkbook.com>
doesn’t have deployment of static pages correctly worked out for their site.
Copy code
import * as sst from "@serverless-stack/resources";
import { RemovalPolicy } from "aws-cdk-lib";
import { Source, s3Deployment } from "aws-cdk-lib/aws-s3-deployment";

export default class MarketingStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const { api } = props;

    const staticSite = new sst.StaticSite(this, "Site", {
      path: "website",
      errorPage: "404.html",
      buildOutput: "public",
      buildCommand: "npm run build",
      environment: {
        GATSBY_API_URL: api.url,
      },
      s3Bucket: {
        publicReadAccess: true,
        removalPolicy: RemovalPolicy.DESTROY,
        websiteIndexDocument: "index.html",
      },
    });

    new s3Deployment.BucketDeployment(this, "deployStaticWebsite", {
      sources: [Source.asset("../website")],
      destinationBucket: staticSite.bucketArn,
    });
t

thdxr

02/12/2022, 4:35 PM
the issue you have is when you go to a nested route it can't find index.html?
d

Devin

02/12/2022, 4:36 PM
yep. p much