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

S3 Static Website Hosting #632

Closed
garrett-hopper opened this issue Aug 27, 2018 · 11 comments
Closed

S3 Static Website Hosting #632

garrett-hopper opened this issue Aug 27, 2018 · 11 comments
Assignees
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved.

Comments

@garrett-hopper
Copy link

Currently an S3 bucket can't be configured with a WebsiteConfiguration.
Is there any sort of escape hatch to do this or would I need to create some sort of custom resource?

I know I could create CloudFront distribution, but I'm not looking to do that at the moment.

@eladb
Copy link
Contributor

eladb commented Aug 28, 2018

Yes, it's a known missing feature. Currently, the only way to work around these types of gaps is to override the toCloudFormation method in your Stack and "patch" the synthesized template.

See #606 for an example on how to implement something like this and a discussion on possible approaches we are considering.

@rix0rrr rix0rrr added the feature-request A feature should be added or improved. label Nov 7, 2018
@debora-ito debora-ito added the @aws-cdk/aws-s3 Related to Amazon S3 label Nov 8, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 8, 2018

@eladb we now have https://awslabs.github.io/aws-cdk/refs/_aws-cdk_aws-s3-deployment.html , so that's great start.

Is there already a way to configure S3 Bucket/CloudFront distribution to host those files, or is that still going down to L1 level?

@eladb
Copy link
Contributor

eladb commented Nov 11, 2018

There is a cloud front L2 which I believe needs quite a lot of work. Also, we need to add support for blue/green deployments of static content as part of s3-deployment

@john-shaskin
Copy link
Contributor

Hey, @Jumblemuddle, are you just looking to set up an s3 bucket as a static website, or something more involved? I've currently been able to set up a publicly readable s3 site with the following snippet.

const websiteBucket = new s3.Bucket(this, 'MyStaticWebsite', {
  websiteIndexDocument: 'index.html',
  websiteErrorDocument: 'error.html'
});
websiteBucket.grantPublicAccess('*', 's3:GetObject');

@rix0rrr rix0rrr added the gap label Jan 4, 2019
@eladb eladb assigned eladb and unassigned eladb Aug 12, 2019
@eladb
Copy link
Contributor

eladb commented Oct 2, 2019

Still relevant

@hoegertn
Copy link
Contributor

hoegertn commented Oct 2, 2019

I have an S3 Website Hosting construct in my library. Maybe this could be integrated: https://github.com/taimos/cdk-constructs/blob/master/lib/web/single-page-app.ts

What do you think?

@spaceemotion
Copy link

@hoegertn Fancy seeing you here. You've linked me on the AWS Community Day to your stack.

The only "problem" I have with it is that it tends to redirect me to /index.html in almost all error cases.

Since I am using a Vue SPA, the router picks it up and simply shows a blank page. Redirecting to "/" so the browser can fetch the index.html on its own would be better (haven't figured out how to configure the CDK code for that yet though).

Otherwise it works as expected, having a blue green deployment would be amazing 👍

@hoegertn
Copy link
Contributor

hoegertn commented Oct 2, 2019

It is not redirecting but returning the content of index.html which is what e.g. Angular recommends for their routing. But this would be configurable in a generic CDK construct.

@spaceemotion
Copy link

Hmm, when I enter http://my-site.com it redirects me to https://my-site.com/index.html

@hoegertn
Copy link
Contributor

hoegertn commented Oct 2, 2019

Yes, Cloudfront is configured with DefaultPage of index.html but if you call foobar.html you get the same content without redirect. This could all be configurable if needed.

@eladb eladb assigned iliapolo and unassigned eladb Jan 23, 2020
@SomayaB SomayaB removed the gap label Feb 25, 2020
@iliapolo iliapolo added the effort/medium Medium work item – several days of effort label Mar 9, 2020
@iliapolo
Copy link
Contributor

Closing as we now have all the WebsiteConfiguration properties: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html

  • websiteErrorDocument
  • websiteIndexDocument
  • websiteRedirect
  • websiteRoutingRules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

9 participants