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

Austin

03/22/2022, 7:01 PM
Is there any way to enable Origin Shield with
sst.StaticSite
?
f

Frank

03/23/2022, 2:46 AM
Hey @Austin, can u give this a try:
Copy code
import * as cf from "aws-cdk-lib/aws-cloudfront";

const site;

site = new StaticSite(this, "Site", {
  path: "path/to/src",
  cfDistribution: {
    defaultBehavior: {
      origin: Lazy.any({
        produce(context) {
          return new cfOrigins.S3Origin(site.s3Bucket, {
            originShieldRegion: "us-east-1",
          });
        }
      }),
      viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
    },
  },
});
It might be a bit jarring at first, but what we are doing here is overriding the
defaultBehavior
of the distribution.
The tricky thing here is that we need to access the
s3Bucket
created internally in the
StaticSite
. And
Lazy.any
allows us to do that.
Let me know if this works for you.
4 Views