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:
WebsiteConfigurationCodeUri which points to the assets directory to upload to S3.CodeUri should be optional to allow users to handle UI deployments external to SAM.Please describe your use case and let us know how SAM could make it easier for you to create websites.
This would be very helpful currently i have already done this by using CodePipeline, CodeBuild and CFN resources with CustomResources as followed:
OutputArtifactsSourceBucketName & SourceObjectKey parameter that points to the OutputArtifactIdentityPoolId, 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.
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.
+1
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:
These are great. Thanks for the input so far!
I think a CloudFront OAI is preferrable to using a WebsiteConfiguration on an S3 bucket.
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.
Every single page webapp and static generators could benefit (Angular, React, Ember, Jekyll, ... )
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?
@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 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.
Maybe it's worth wrapping this into a serverless transform? https://github.com/serverlesspub/cloudformation-deploy-to-s3/blob/master/example/template.yml
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 + Cloudfront stack that DependsOn API 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.
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.
In the API Gateway Developer Portal, we're currently copying it into a simple lambda so we can upload it to an S3 bucket, so we can support one-click install through SAR. Something like CodeUri would be far more ideal, since we could avoid the need for the intermediate lambda that just does a recursive tree walk.
@praneetap thank you for looking into this feature! It would be of great help if you could please provide an update on this
Most helpful comment
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.