|
2 | 2 |
|
3 | 3 | This project builds an [AWS Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) to deploy files to S3 buckets as part of a CloudFormation deployment. Using [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html), you can use a Lambda function and a [CloudFormation Custom Resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html) to upload files to your S3 bucket. All the deployment logic is baked into the layer provided by this project so the only things needed from the consumer is the files, the generated Lambda function, and the permissions to deploy to the bucket. Here is a minimal example of how to use it. |
4 | 4 |
|
| 5 | +This project used to recommend taking a dependency on a layer exposed by this project's AWS account. This has numerous issues including security concerns from consumers and difficulty exposing the latest version of the layer. Going forward, this project will release the layer as a zip file available in each release of the project. |
| 6 | + |
5 | 7 | ## Example CloudFormation Template |
6 | 8 |
|
| 9 | +**Preferred method of consumption** |
| 10 | + |
| 11 | +```yaml |
| 12 | +AWSTemplateFormatVersion: "2010-09-09" |
| 13 | +Transform: AWS::Serverless-2016-10-31 |
| 14 | +Parameters: |
| 15 | + DeploymentContentVersion: |
| 16 | + Type: String |
| 17 | + Description: This can be any unique string that identifies the current set of files you are deploying. |
| 18 | +Resources: |
| 19 | + WebsiteBucket: |
| 20 | + Type: AWS::S3::Bucket |
| 21 | + S3UploadLambdaLayer: |
| 22 | + Type: AWS::Serverless::LayerVersion |
| 23 | + Properties: |
| 24 | + ContentUri: local/path/to/layer.zip # This is the layer downloaded from a release of this project |
| 25 | + S3UploadLambda: |
| 26 | + Type: AWS::Serverless::Function |
| 27 | + Properties: |
| 28 | + Layers: [!Ref S3UploadLambdaLayer] |
| 29 | + CodeUri: |
| 30 | + local/path/to/assets # This is a local path to a folder of files you want to deploy, |
| 31 | + # either your build or source directory, depending on how your |
| 32 | + # site is configured. |
| 33 | + Handler: |
| 34 | + s3-upload-custom-resource.handler # This is fixed and references a file provided by |
| 35 | + # this project and available in the Lambda layer. |
| 36 | + Runtime: nodejs12.x |
| 37 | + Policies: |
| 38 | + - S3CrudPolicy: |
| 39 | + BucketName: !Ref WebsiteBucket |
| 40 | + DeployWebsite: |
| 41 | + Type: Custom::UploadFilesToS3 |
| 42 | + Properties: |
| 43 | + ServiceToken: !GetAtt S3UploadLambda.Arn |
| 44 | + BucketName: !Ref WebsiteBucket |
| 45 | + ContentVersion: !Ref DeploymentContentVersion |
| 46 | +``` |
| 47 | +
|
| 48 | +**Legacy method of consumption** |
| 49 | +
|
7 | 50 | ```yaml |
8 | 51 | AWSTemplateFormatVersion: "2010-09-09" |
9 | 52 | Transform: AWS::Serverless-2016-10-31 |
|
0 commit comments