Is there any way to enable Origin Shield with `sst...
# help
a
Is there any way to enable Origin Shield with
sst.StaticSite
?
f
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.