You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SAM should provide a way to easily create static websites hosted on S3 and CloudFront. The purpose of this Issue is to gather requirements from the community to ensure we address primary use-cases.
Requirements:
Create an S3 Bucket configured with WebsiteConfiguration
Option for enabling S3 redirect configuration for clean SPA routes
Allow specifying CodeUri which points to the assets directory to upload to S3.
Currently, Lambda Functions get uploaded to an existing S3 Bucket prior to SAM transformation, whereas the S3 bucket for websites will be created within the stack. One option is to upload to an existing S3 Bucket (the same one used for Lambda and APIs) and have a CloudFormation Custom Resource for copying to the Website S3 bucket.
The same Custom Resource could be used for deployments (invalidate CloudFront cache)
CodeUri should be optional to allow users to handle UI deployments external to SAM.
We may decide to punt the CodeUri/Deployment story as a follow-up so that we can deliver the infrastructure story first.
Create a CloudFront distribution to provide caching, edge nodes, custom domain support, etc.
CloudFront distribution should provide opinionated defaults, but all properties should be configurable by end user
Allow for specifying a custom domain name
Route53 configuration
ACM Certificate (optionally pass in your own)
Support for redirecting non-www to www
Please describe your use case and let us know how SAM could make it easier for you to create websites.
Reacted by Bryson Tyrrell, Daniel Roschka, jaxondu, Joris Conijn, Mads Toftum, Ryan Means, Andrew O'Hara, tuomov-tieto, Martin, Matteo Figus and 49 more
These steps are used by web applications that are build for Aurelia or Angular they have a build system that point to a specific version in the index.html file: /app.[SOME_HASH].bundle.js.
Reacted by Brett Andrews, Sean Yu, Ben Kehoe and Sandeep Kunkunuru
Ideally, for me, I'd like SAM to handle the bucket content and not any of the configuration. This has use cases past just static web content.
Something fairly simple such as:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
WebBucket:
Type: AWS::S3:Bucket
WebBucketContent:
Type: AWS::Serverless::BucketContent
Properties:
BucketName: !Ref WebBucket
ContentUri: ./path/to/content/dir
SyncOptions: # Optional: Default behavior is to sync the Bucket's content with the artifact exactly
- IgnoreExisting # Do not overwrite existing files in the Bucket
- Preserve # Do not delete files in the Bucket not in the artifact
During the package process the ContentUri location would be zipped up and uploaded to the S3 Bucket SAM is sending artifacts to and the value replaced with the S3 URI - identically to how Lambda packages are handled.
Then during deployment the custom CloudFormation resource can pull in that content artifact and perform the appropriate sync operation with the target bucket.
Reacted by Brett Andrews, balazs4, Daniel King, Muaz Othman, arnvlnc, Narayan Singhal, Billy Bunn, CM Simmons and Sandeep Kunkunuru
One of the things that i have ran into is that i needed to set the ContentType to text/html and so on else CloudFront will force download the file from S3.
@brettstack do you have a general idea how this feature will work in SAM and what we can do to help out?
There was also the recently released Amplify Console https://aws.amazon.com/about-aws/whats-new/2018/11/announcing-aws-amplify-console/ so we want to consider this as an option, e.g you can set Provider to "AmplifyConsole" to use that, or leave it blank to default to having SAM create all the necessary resources for you (S3, CloudFront, Route53, etc.) if you want more control.
We're still gathering feedback and customer requirements, but I will tell you that this is one feature I'm particularly excited about and will check back in when I have an RFC.
Would this be applicable to static content for dynamic websites?
I recently ported our registration system to a "razor pages" (lightweight dotnet core) project running as a lambda. We're trialing this at the moment as it potentially provides a much simpler way of deploying some of our sites, but serving assets (images, fonts, pdfs) via lambda is a bit wasteful. It would be great if there was an in built way to split the hosting of dynamic content and static content.
I know this is a proposal for Static Websites, elaborating further on @faermanj's suggestion, I think it could very well extend to following architecture:
A nested Stack to host assets from a Single Page Application (SPA) created with S3 + CloudFront
Another nested RESTful API / graphql stack that exports the API Endpoint created with API Gateway + Lambda.
A top level stack that nests the aforementioned stacks and the S3 + Cloudfront stack that DependsOnAPI Gateway + Lambda stack to finish and export the API Gateway Endpoint that could be passed on to the S3+Cloudfront stack. This top level stack can share S3 buckets across the nested stacks conserving.
At my organization, I am trying to push for SAM based deployment for our Full Stack SPA/MPA based Javascript Projects. IMHO a ton of projects that could easily be refactored from Ec2 /ALB based deployments to serverless if the above can be achieved.
Hello! Could you elaborate on the status of this feature please? I'm looking into AWS cloud infrastructure for my next project and I'm choosing between AWS SAM and Serverless Framework to manage it. And I'm a bit surprised that SAM doesn't provide a straightforward way to deploy static content (by looking at the docs at least).
Thanks for reaching out @slavafomin. We recently finalized our design for custom domains (2 and 3 in this proposal) and it will certainly help towards this feature. Please take a look at Custom Domains Project Board to track our progress on it.
Activity
Nr18 commentedon Oct 12, 2018
This would be very helpful currently i have already done this by using CodePipeline, CodeBuild and CFN resources with CustomResources as followed:
OutputArtifactsSourceBucketName&SourceObjectKeyparameter that points to theOutputArtifactIdentityPoolId,UserPoolId,UserPoolWebClientId,AppSyncEndpoint,CloudFrontDistributionIdThese steps are used by web applications that are build for Aurelia or Angular they have a build system that point to a specific version in the index.html file:
/app.[SOME_HASH].bundle.js.brysontyrrell commentedon Oct 12, 2018
Ideally, for me, I'd like SAM to handle the bucket content and not any of the configuration. This has use cases past just static web content.
Something fairly simple such as:
During the
packageprocess theContentUrilocation would be zipped up and uploaded to the S3 Bucket SAM is sending artifacts to and the value replaced with the S3 URI - identically to how Lambda packages are handled.Then during deployment the custom CloudFormation resource can pull in that content artifact and perform the appropriate sync operation with the target bucket.
bjornadolfsson commentedon Oct 15, 2018
+1
rmmeans commentedon Oct 15, 2018
I like the spirit behind this idea! A very common task that many orgs have to do frequently and there are multiple steps involved.
I would suggest one more feature to add to your list:
The ability to automatically setup a L@E function on the CDN that can add headers to the response from the S3 origin prior to being cached. This is a pretty common task now for static sites and one that AWS has blogged about in the past for a lambda@edge use case: https://aws.amazon.com/blogs/networking-and-content-delivery/adding-http-security-headers-using-lambdaedge-and-amazon-cloudfront/
brettstack commentedon Oct 22, 2018
These are great. Thanks for the input so far!
kadrach commentedon Oct 30, 2018
I think a CloudFront OAI is preferrable to using a WebsiteConfiguration on an S3 bucket.
benkehoe commentedon Nov 9, 2018
I'd like CodeUri to be able to be either a list, overlaying multiple directories into the same space, or a map, with the keys being prefixes.
I'm on board with @brysontyrrell that web hosting is less important to me than just deployment of objects.
faermanj commentedon Nov 15, 2018
Every single page webapp and static generators could benefit (Angular, React, Ember, Jekyll, ... )
Nr18 commentedon Nov 16, 2018
One of the things that i have ran into is that i needed to set the ContentType to
text/htmland so on else CloudFront will force download the file from S3.@brettstack do you have a general idea how this feature will work in SAM and what we can do to help out?
brettstack commentedon Nov 27, 2018
@Nr18 I have a general idea as I've done this setup before. This repo by Eric Hammond is similar to what we have in mind https://github.com/alestic/aws-git-backed-static-website.
There was also the recently released Amplify Console https://aws.amazon.com/about-aws/whats-new/2018/11/announcing-aws-amplify-console/ so we want to consider this as an option, e.g you can set
Providerto "AmplifyConsole" to use that, or leave it blank to default to having SAM create all the necessary resources for you (S3, CloudFront, Route53, etc.) if you want more control.We're still gathering feedback and customer requirements, but I will tell you that this is one feature I'm particularly excited about and will check back in when I have an RFC.
AlexHarper commentedon Dec 12, 2018
Would this be applicable to static content for dynamic websites?
I recently ported our registration system to a "razor pages" (lightweight dotnet core) project running as a lambda. We're trialing this at the moment as it potentially provides a much simpler way of deploying some of our sites, but serving assets (images, fonts, pdfs) via lambda is a bit wasteful. It would be great if there was an in built way to split the hosting of dynamic content and static content.
gojko commentedon Jan 25, 2019
Maybe it's worth wrapping this into a serverless transform? https://github.com/serverlesspub/cloudformation-deploy-to-s3/blob/master/example/template.yml
vikikamath commentedon Jul 22, 2019
I know this is a proposal for Static Websites, elaborating further on @faermanj's suggestion, I think it could very well extend to following architecture:
S3 + CloudFrontAPI Gateway + Lambda.S3 + Cloudfrontstack thatDependsOnAPI Gateway + Lambdastack to finish and export theAPI GatewayEndpoint that could be passed on to theS3+Cloudfrontstack. This top level stack can shareS3buckets across the nested stacks conserving.At my organization, I am trying to push for SAM based deployment for our Full Stack SPA/MPA based Javascript Projects. IMHO a ton of projects that could easily be refactored from
Ec2 /ALBbased deployments toserverlessif the above can be achieved.slavafomin commentedon Sep 11, 2019
Hello! Could you elaborate on the status of this feature please? I'm looking into AWS cloud infrastructure for my next project and I'm choosing between AWS SAM and Serverless Framework to manage it. And I'm a bit surprised that SAM doesn't provide a straightforward way to deploy static content (by looking at the docs at least).
praneetap commentedon Sep 11, 2019
Thanks for reaching out @slavafomin. We recently finalized our design for custom domains (2 and 3 in this proposal) and it will certainly help towards this feature. Please take a look at Custom Domains Project Board to track our progress on it.
jplock commentedon Jan 28, 2020
Related to this, I created a SAM project called https://github.com/smoketurner/sam-cdn and is available within the Serverless Application Repository at https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:860114833029:applications~cloudfront-cdn that aims to simplify this pattern I was repeating over and over again.
This pattern allows you to plugin API Gateway or AppSync with a custom domain fairly easily and using CloudFront + S3 for static content serving.
rockyadi commentedon Apr 30, 2020
@praneetap thank you for looking into this feature! It would be of great help if you could please provide an update on this