|
2 | 2 |
|
3 | 3 | [](https://github-actions.netlify.com/py-lambda) |
4 | 4 |
|
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. |
6 | 6 |
|
7 | 7 | ## 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 | + |
9 | 13 | ### Structure |
10 | 14 | - 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 | + |
12 | 17 | ### Environment variables |
13 | 18 | Stored as secrets or env vars, doesn't matter. But also please don't put your AWS keys outside Secrets. |
14 | 19 | - **AWS Credentials** |
15 | 20 | 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` |
17 | 24 | 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` |
19 | 26 | 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: |
20 | 27 | - Function name - `my-function` |
21 | 28 | - Function ARN - `arn:aws:lambda:us-west-2:123456789012:function:my-function` |
22 | 29 | - Partial ARN - `123456789012:function:my-function` |
| 30 | +- `requirements_txt` |
| 31 | + The name/path for the `requirements.txt` file. Defaults to `requirements.txt`. |
23 | 32 |
|
24 | 33 |
|
25 | 34 | ### 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' |
49 | 56 |
|
50 | 57 | ``` |
0 commit comments