Skip to content

Commit 8bc9658

Browse files
author
Josh Rosenberg
committed
add option to upload dependency layer to S3 first
1 parent 5c8e766 commit 8bc9658

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ In order for the Action to have access to the code, you must use the `actions/ch
1616

1717
### Environment variables
1818
Stored as secrets or env vars, doesn't matter. But also please don't put your AWS keys outside Secrets.
19-
- **AWS Credentials**
19+
- **AWS Credentials**
2020
That includes the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, etc. It's used by `awscli`, so the docs for that [can be found here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html).
2121

2222
### Inputs
23-
- `lambda_layer_arn`
23+
- `lambda_layer_arn`
2424
The ARN for the Lambda layer the dependencies should be pushed to **without the version** (every push is a new version).
25-
- `lambda_function_name`
25+
- `lambda_function_name`
2626
The Lambda function name. [From the AWS docs](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html), it can be any of the following:
27-
- Function name - `my-function`
28-
- Function ARN - `arn:aws:lambda:us-west-2:123456789012:function:my-function`
27+
- Function name - `my-function`
28+
- Function ARN - `arn:aws:lambda:us-west-2:123456789012:function:my-function`
2929
- Partial ARN - `123456789012:function:my-function`
3030
- `requirements_txt`
3131
The name/path for the `requirements.txt` file. Defaults to `requirements.txt`.
32+
- `use_s3`
33+
Whether to upload the dependency layer zip to S3 (required if the zip exceeds 50MB) or not. (If not, it's uploaded directly to Lambda.) Defaults to `false`.
34+
- `s3_bucket_name`
35+
The S3 bucket name used if you are uploading the dependency layer to S3.
3236

3337

3438
### Example workflow
@@ -41,7 +45,7 @@ on:
4145
jobs:
4246
build:
4347
runs-on: ubuntu-latest
44-
48+
4549
steps:
4650
- uses: actions/checkout@master
4751
- name: Deploy code to Lambda

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ inputs:
1212
lambda_function_name:
1313
description: The Lambda function name. Check the AWS docs/readme for examples.
1414
required: true
15+
use_s3:
16+
description: Whether to use S3 (true) or not (false) for the dependencies layer upload.
17+
required: false
18+
default: 'false'
19+
s3_bucket_name:
20+
description: The S3 bucket name for the dependencies layer upload.
21+
required: false
22+
default: no-bucket-name-here
1523
runs:
1624
using: 'docker'
1725
image: 'Dockerfile'

entrypoint.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ install_zip_dependencies(){
99
}
1010

1111
publish_dependencies_as_layer(){
12-
echo "Publishing dependencies as a layer..."
13-
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip)
14-
LAYER_VERSION=$(jq '.Version' <<< "$result")
12+
if [ "$INPUT_USE_S3" = true ]
13+
then
14+
echo "Uploading dependencies to S3..."
15+
aws s3 cp dependencies.zip s3://"${INPUT_S3_BUCKET_NAME}"/dependencies.zip
16+
echo "Publishing dependencies from S3 as a layer..."
17+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content S3Bucket="${INPUT_S3_BUCKET_NAME}",S3Key=dependencies.zip)
18+
LAYER_VERSION=$(jq '.Version' <<< "$result")
19+
else
20+
echo "Publishing dependencies as a layer..."
21+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip)
22+
LAYER_VERSION=$(jq '.Version' <<< "$result")
23+
fi
1524
rm -rf python
1625
rm dependencies.zip
1726
}

0 commit comments

Comments
 (0)