Skip to content

Commit 5e622f6

Browse files
committed
Convert consumption mechanism to be the layer zip instead of consuming the layer directly
1 parent f005e6d commit 5e622f6

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.github/workflows/npm.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ jobs:
3434
- name: Release
3535
if: github.ref == 'refs/heads/main'
3636
run: npm run release
37+
- name: GitHub Release
38+
if: github.ref == 'refs/heads/main'
39+
uses: ncipollo/release-action@v1
40+
with:
41+
artifacts: dist/layer.zip
42+
token: ${{ secrets.GITHUB_TOKEN }}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
# Unsupported types
1414
*.txt
1515
.gitignore
16+
.nvmrc
1617
.prettierignore
1718
LICENSE

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,51 @@
22

33
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.
44

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+
57
## Example CloudFormation Template
68

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+
750
```yaml
851
AWSTemplateFormatVersion: "2010-09-09"
952
Transform: AWS::Serverless-2016-10-31

0 commit comments

Comments
 (0)