Skip to content

Commit

Permalink
Convert consumption mechanism to be the layer zip instead of consumin…
Browse files Browse the repository at this point in the history
…g the layer directly
  • Loading branch information
quittle committed Apr 5, 2021
1 parent f005e6d commit 5e622f6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ jobs:
- name: Release
if: github.ref == 'refs/heads/main'
run: npm run release
- name: GitHub Release
if: github.ref == 'refs/heads/main'
uses: ncipollo/release-action@v1
with:
artifacts: dist/layer.zip
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
# Unsupported types
*.txt
.gitignore
.nvmrc
.prettierignore
LICENSE
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,51 @@

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.

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.

## Example CloudFormation Template

**Preferred method of consumption**

```yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Parameters:
DeploymentContentVersion:
Type: String
Description: This can be any unique string that identifies the current set of files you are deploying.
Resources:
WebsiteBucket:
Type: AWS::S3::Bucket
S3UploadLambdaLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: local/path/to/layer.zip # This is the layer downloaded from a release of this project
S3UploadLambda:
Type: AWS::Serverless::Function
Properties:
Layers: [!Ref S3UploadLambdaLayer]
CodeUri:
local/path/to/assets # This is a local path to a folder of files you want to deploy,
# either your build or source directory, depending on how your
# site is configured.
Handler:
s3-upload-custom-resource.handler # This is fixed and references a file provided by
# this project and available in the Lambda layer.
Runtime: nodejs12.x
Policies:
- S3CrudPolicy:
BucketName: !Ref WebsiteBucket
DeployWebsite:
Type: Custom::UploadFilesToS3
Properties:
ServiceToken: !GetAtt S3UploadLambda.Arn
BucketName: !Ref WebsiteBucket
ContentVersion: !Ref DeploymentContentVersion
```
**Legacy method of consumption**
```yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Expand Down

0 comments on commit 5e622f6

Please sign in to comment.