-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Static Site 403's for route based index pages (Cloudfront + s3 issue) #1332
Comments
Doing some more work on this. I find: https://github.com/aws-samples/aws-cdk-examples/blob/master/typescript/static-site/static-site.ts Which looks like what |
I have a possible solution here. I'm going to try to play with this some this week. I'll update the thread with info if it works. |
Hi @aisflat439, give this a try. This override the S3 bucket and the CloudFront distribution based on what you shared above: const site = new sst.StaticSite(this, "GatsbySite", {
...,
s3Bucket: {
websiteIndexDocument: "index.html",
websiteErrorDocument: "404.html",
},
cfDistribution: {
defaultBehavior: {
origin: new cfOrigins.HttpOrigin(
Lazy.stringValue({
produce() {
return site.s3Bucket.bucketWebsiteUrl;
}
})
),
},
},
}); In short, pass in the Current, the if (s3Bucket.websiteIndexDocument) {
throw new Error(
`Do not configure the "s3Bucket.websiteIndexDocument". Use the "indexPage" to configure the StaticSite index page.`
);
} Give this a try, if it works for you, I will make a change to allow overriding |
I misunderstood this. There might be more I need to try here |
@fwang I'm way unfamiliar with this but I think this line is the problem. I don't know how to test it though as the only way that I can test it is to deploy it and then I'm using the package that has the potential issue. According to the note in this README the index document that SST is disallowing, handles this exact behavior. Does that seem possible to you? |
@aisflat439 yeah, actually that's what I meant in the previous comment to comment out the two Like I mentioned on Slack, if you can put together a sample repo with SST + Gastby that can reproduce this issue, I will give it a try on my end. |
Hey @fwang. Here's the example. I tried to keep it as minimal as possible. You have 2 urls in this case:
if you run
which should be the document returned for the route You can see a deployed example here: My understanding of StaticSite leads me to believe that this should apply to any website using the Static Site Construct. I'm happy to help in any way I can and will provide more information if you need anything. I didn't bother actually deploying the example below since I'd guess you'll want to see it on your own. Please let me know if you have any luck or I'm just a bonehead 😄 . |
@fwang Is there anything else I can do to help you reproduce the issue at all? |
The websiteIndexDocument is needed to turn s3 into a webserver https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment-readme.html |
I think work around is to extend StaticSite and override createS3Bucket function |
Has this issue any solution? Has anyone find any workaround? I'm using |
Indeed @fjinkis! This is fixed in SST-2 with the new Static Site Construct. Although I've left gatsby behind for astro |
@aisflat439 Do you think that I should migrate from |
Are there any news about this issue? I got the same error using sst 2 with |
@minizwergi there is a bug fix in 2.5.1 version. Take a look at this issue |
I'm fully stumped on this issue.
I followed the suggested implementation for a gatsby site here. My gatsby site builds a few pages
If you navigate to
/
then use a<Link />
tag (from gatsby) everything works correctly. Because the app is hydrated. However, if you/blog
you get a 403. A gatsby site will reload though, becuase of the hydration. As an example, on my site you can see that on refresh we get a 403 for this file:however, I can see it in s3 here:
Gatsby has a plugin for this https://gatsby-plugin-s3.jari.io/recipes/with-cloudfront/ that solves this issue. According to that plugin, in order to make an s3 bucket work, you need it to be public. That means you need to
I looked at the aws docs and I see https://docs.aws.amazon.com/AmazonS3/latest/userguide/EnableWebsiteHosting.html which seems to say that you need to select Use This Bucket to enable static hosting. I don't see how to do that in SST or CDK.
perhaps the better solution I should try is https://docs.aws.amazon.com/cdk/api/v2/docs/aws-amplify-alpha-readme.html which side steps the issue I guess? I dunno. I've been messing with this for 2 weeks now. 😭 and am fully out of ideas.
The text was updated successfully, but these errors were encountered: