Skip to content

Commit c94e2f7

Browse files
authored
Merge pull request #5 from mariamrf/v2
Migrate to v2 of Github Actions
2 parents 022d22c + c76ef7c commit c94e2f7

File tree

4 files changed

+63
-40
lines changed

4 files changed

+63
-40
lines changed

Dockerfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
FROM python:3.6
22

3-
LABEL "com.github.actions.name"="Py Lambda Deploy"
4-
LABEL "com.github.actions.description"="Deploy python code to AWS Lambda with dependencies in a separate layer."
5-
LABEL "com.github.actions.icon"="layers"
6-
LABEL "com.github.actions.color"="yellow"
7-
8-
LABEL "repository"="http://github.com/mariamrf/py-lambda-action"
9-
LABEL "maintainer"="Mariam Maarouf <mrf.mariam@gmail.com>"
10-
113
RUN apt-get update
124
RUN apt-get install -y jq zip
135
RUN pip install awscli

README.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,56 @@
22

33
[![GitHubActions](https://img.shields.io/badge/listed%20on-GitHubActions-blue.svg)](https://github-actions.netlify.com/py-lambda)
44

5-
A Github Action to deploy AWS Lambda functions written in Python with their dependencies in a separate layer. For now, only works with Python 3.6.
5+
A Github Action to deploy AWS Lambda functions written in Python with their dependencies in a separate layer. For now, only works with Python 3.6. PRs welcome.
66

77
## Use
8-
Doesn't take any arguments. Deploys everything in the repo as code to the Lambda function, and installs/zips/deploys the dependencies as a separate layer the function can then immediately use.
8+
Deploys everything in the repo as code to the Lambda function, and installs/zips/deploys the dependencies as a separate layer the function can then immediately use.
9+
10+
### Pre-requisites
11+
In order for the Action to have access to the code, you must use the `actions/checkout@master` job before it. See the example below.
12+
913
### Structure
1014
- Lambda code should be structured normally/as Lambda would expect it.
11-
- **Dependencies must be stored in a `requirements.txt`**.
15+
- **Dependencies must be stored in a `requirements.txt`** or a similar file (provide the filename explicitly if that's the case).
16+
1217
### Environment variables
1318
Stored as secrets or env vars, doesn't matter. But also please don't put your AWS keys outside Secrets.
1419
- **AWS Credentials**
1520
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).
16-
- `LAMBDA_LAYER_ARN`
21+
22+
### Inputs
23+
- `lambda_layer_arn`
1724
The ARN for the Lambda layer the dependencies should be pushed to **without the version** (every push is a new version).
18-
- `LAMBDA_FUNCTION_NAME`
25+
- `lambda_function_name`
1926
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:
2027
- Function name - `my-function`
2128
- Function ARN - `arn:aws:lambda:us-west-2:123456789012:function:my-function`
2229
- Partial ARN - `123456789012:function:my-function`
30+
- `requirements_txt`
31+
The name/path for the `requirements.txt` file. Defaults to `requirements.txt`.
2332

2433

2534
### Example workflow
26-
```hcl
27-
workflow "Build & deploy" {
28-
on = "push"
29-
resolves = ["py-lambda-deploy"]
30-
}
31-
32-
action "py-lambda-deploy" {
33-
needs = "Master"
34-
uses = "mariamrf/py-lambda-action@master"
35-
secrets = [
36-
"AWS_ACCESS_KEY_ID",
37-
"AWS_SECRET_ACCESS_KEY",
38-
"AWS_DEFAULT_REGION",
39-
"LAMBDA_FUNCTION_NAME",
40-
"LAMBDA_LAYER_ARN",
41-
]
42-
}
43-
44-
# Filter for master branch
45-
action "Master" {
46-
uses = "actions/bin/filter@master"
47-
args = "branch master"
48-
}
35+
```yaml
36+
name: deploy-py-lambda
37+
on:
38+
push:
39+
branches:
40+
- master
41+
jobs:
42+
build:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@master
47+
- name: Deploy code to Lambda
48+
uses: mariamrf/py-lambda-action@v1.0.0
49+
with:
50+
lambda_layer_arn: 'arn:aws:lambda:us-east-2:123456789012:layer:my-layer'
51+
lambda_function_name: 'my-function'
52+
env:
53+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
54+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
55+
AWS_REGION: 'us-east-2'
4956

5057
```

action.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Py Lambda Deploy
2+
author: Mariam Maarouf
3+
description: Deploy python code to AWS Lambda with dependencies in a separate layer.
4+
inputs:
5+
requirements_txt:
6+
description: the name/path to the requirements.txt file
7+
required: true
8+
default: 'requirements.txt'
9+
lambda_layer_arn:
10+
description: The ARN for the Lambda layer the dependencies should be pushed to without the version (every push is a new version).
11+
required: true
12+
lambda_function_name:
13+
description: The Lambda function name. Check the AWS docs/readme for examples.
14+
required: true
15+
runs:
16+
using: 'docker'
17+
image: 'Dockerfile'
18+
args:
19+
- ${{ inputs.requirements_txt }}
20+
- ${{ inputs.lambda_layer_arn }}
21+
- ${{ inputs.lambda_function_name }}
22+
branding:
23+
icon: 'layers'
24+
color: 'yellow'

entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
install_zip_dependencies(){
44
echo "Installing and zipping dependencies..."
55
mkdir python
6-
pip install --target=python -r "${INPUT_REQUIREMENTS_TXT:-requirements.txt}"
6+
pip install --target=python -r "${INPUT_REQUIREMENTS_TXT}"
77
zip -r dependencies.zip ./python
88
}
99

1010
publish_dependencies_as_layer(){
1111
echo "Publishing dependencies as a layer..."
12-
local result=$(aws lambda publish-layer-version --layer-name "${LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip)
12+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip)
1313
LAYER_VERSION=$(jq '.Version' <<< "$result")
1414
rm -rf python
1515
rm dependencies.zip
@@ -18,12 +18,12 @@ publish_dependencies_as_layer(){
1818
publish_function_code(){
1919
echo "Deploying the code itself..."
2020
zip -r code.zip . -x \*.git\*
21-
aws lambda update-function-code --function-name "${LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip
21+
aws lambda update-function-code --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip
2222
}
2323

2424
update_function_layers(){
2525
echo "Using the layer in the function..."
26-
aws lambda update-function-configuration --function-name "${LAMBDA_FUNCTION_NAME}" --layers "${LAMBDA_LAYER_ARN}:${LAYER_VERSION}"
26+
aws lambda update-function-configuration --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --layers "${INPUT_LAMBDA_LAYER_ARN}:${LAYER_VERSION}"
2727
}
2828

2929
deploy_lambda_function(){

0 commit comments

Comments
 (0)