Skip to content
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

Use S3 website URL rather than REST endpoint #22

Open
clarkd opened this issue Mar 2, 2020 · 3 comments
Open

Use S3 website URL rather than REST endpoint #22

clarkd opened this issue Mar 2, 2020 · 3 comments

Comments

@clarkd
Copy link

clarkd commented Mar 2, 2020

When the plugin creates the CF distribution it uses the REST endpoint for the S3 bucket, this means you get XML style error pages and means you lose out on SSL offloading and HTML errors.

I.e. it currently configures CF to point at:

xxxxxxx-app.s3.amazonaws.com (REST endpoint)

Rather than the website endpoint:

xxxxxxx-app.s3-website-us-east-1.amazonaws.com (website endpoint).

Note the s3-website in the URL.

More info here: https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html

Is this behaviour configurable? Or have I overlooked something?

@benheymink
Copy link

Update - this only seems to occur if singlePageApp is set to true. Looks like the difference is between the following in index.js:

'Fn::GetAtt': ["WebAppS3Bucket", "WebsiteURL"]

and the following from the resources.yml:

Fn::GetAtt: [WebAppS3Bucket, DomainName]

Any reason not to use the WebsiteURL rather than the DomainName from S3 for both cases?

@andrewphahn
Copy link

This is caused by singlePageApp : true, which uses the REST API for S3 as the origin in CloudFront. When using the API CloudFront will route any request that returns a 503 to /index.html, which is what you want for a single page app. With the S3 HTTP endpoint as the origin you loose this functionality.

What configuration is causing you to see an XML style error page? I would expect it would simply route the request to your configured error page.

@sourcier
Copy link

sourcier commented Apr 9, 2020

When I create an app with the following config:

service: musical-waffle

plugins:
  - fullstack-serverless

custom:
  fullstack:
    bucketName: frontend
    distributionFolder: build
    clientCommand: npm run build    
    errorDocument: index.html
    noConfirm: true
    singlePageApp: true

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage}
  region: eu-west-2
  profile: serverless

I get http 403 errors when I try to access the files in the bucket, if I change singlePageApp to false then it works correctly, my frontend is a React app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants