|
3 | 3 | [](https://github.com/cisagov/skeleton-aws-lambda-python/actions) |
4 | 4 |
|
5 | 5 | This is a generic skeleton project that can be used to quickly get a |
6 | | -new [cisagov](https://github.com/cisagov) GitHub project started. |
7 | | -This skeleton project contains [licensing information](LICENSE), as |
| 6 | +new [cisagov](https://github.com/cisagov) GitHub |
| 7 | +[AWS Lambda](https://aws.amazon.com/lambda/) project using the Python runtimes |
| 8 | +started. This skeleton project contains [licensing information](LICENSE), as |
8 | 9 | well as [pre-commit hooks](https://pre-commit.com) and |
9 | 10 | [GitHub Actions](https://github.com/features/actions) configurations |
10 | 11 | appropriate for the major languages that we use. |
11 | 12 |
|
12 | | -In many cases you will instead want to use one of the more specific |
13 | | -skeleton projects derived from this one. |
| 13 | +## Building the base Lambda image ## |
| 14 | + |
| 15 | +The base Lambda image can be built with the following command: |
| 16 | + |
| 17 | +```console |
| 18 | +docker compose build |
| 19 | +``` |
| 20 | + |
| 21 | +This base image is used both to build a deployment package and to run the |
| 22 | +Lambda locally. |
| 23 | + |
| 24 | +## Building a deployment package ## |
| 25 | + |
| 26 | +You can build a deployment zip file to use when creating a new AWS Lambda |
| 27 | +function with the following command: |
| 28 | + |
| 29 | +```console |
| 30 | +docker compose up build_deployment_package |
| 31 | +``` |
| 32 | + |
| 33 | +This will output the deployment zip file in the root directory. |
| 34 | + |
| 35 | +## Running the Lambda locally ## |
| 36 | + |
| 37 | +The configuration in this repository allows you run the Lambda locally for |
| 38 | +testing as long as you do not need explicit permissions for other AWS |
| 39 | +services. This can be done with the following command: |
| 40 | + |
| 41 | +```console |
| 42 | +docker compose up --detach run_lambda_locally |
| 43 | +``` |
| 44 | + |
| 45 | +You can then invoke the Lambda using the following: |
| 46 | + |
| 47 | +```console |
| 48 | + curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' |
| 49 | +``` |
| 50 | + |
| 51 | +The `{}` in the command is the invocation event payload to send to the Lambda |
| 52 | +and would be the value given as the `event` argument to the handler. |
| 53 | + |
| 54 | +Once you are finished you can stop the detached container with the following command: |
| 55 | + |
| 56 | +```console |
| 57 | +docker compose down |
| 58 | +``` |
| 59 | + |
| 60 | +## How to update Python dependencies ## |
| 61 | + |
| 62 | +The Python dependencies are maintained using a [Pipenv](https://github.com/pypa/pipenv) |
| 63 | +configuration for each supported Python version. Changes to requirements |
| 64 | +should be made to the respective `src/py<Python version>/Pipfile`. More |
| 65 | +information about the `Pipfile` format can be found [here](https://pipenv.pypa.io/en/latest/basics/#example-pipfile-pipfile-lock). |
| 66 | +The accompanying `Pipfile.lock` files contain the specific dependency versions |
| 67 | +that will be installed. These files can be updated like so (using the Python |
| 68 | +3.9 configuration as an example): |
| 69 | + |
| 70 | +```console |
| 71 | +cd src/py3.9 |
| 72 | +pipenv lock |
| 73 | +``` |
14 | 74 |
|
15 | 75 | ## New Repositories from a Skeleton ## |
16 | 76 |
|
|
0 commit comments