Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# aws-lambda-python
An implementation of the Open MPIC API using AWS-Lambda serverless functions written in Python as well as AWS API Gateway.
An implementation of the Open MPIC API using AWS Lambda serverless functions written in Python as well as AWS API Gateway.

# Deployment
As this API runs serverless in the cloud, it is not installed but rather deployed. The below instructions deploy the API in a user's AWS account and create a unique API endpoint for that user.

## Requirements
All requirements for running the API are packaged and uploaded to AWS as a lambda layer. However, the machine deploying the API must have the following requirements
All requirements for running the API are packaged and uploaded to AWS as a Lambda layer. However, the machine deploying the API must have the following requirements:
- The AWS CLI (https://aws.amazon.com/cli/) installed with default profile login credentials. The script currently uses the "default" profile to deploy the API to. If you have multiple AWS profiles, ensure the one you want to use for the API in listed as default in ~/.aws/credentials. You can alternatively change the AWS module parameters in main.tf to use an alternate profile.
- Open Tofu (https://opentofu.org/) is installed. This is an open-source fork of Terraform and the configs in this project are largely interoperable between the two.
- Python 3.11.9 which can be run with the command `python3.11` and `python3`. [pyenv](https://github.com/pyenv/pyenv) is one option for getting this specific version of python and not modifying any other python installs on the system.
Expand All @@ -17,7 +17,7 @@ All requirements for running the API are packaged and uploaded to AWS as a lambd
2. Create a virtual Python environment in the `layer` directory and install the project dependencies via pip. This can be executed by running `hatch run lambda:layer-install`.
3. Package two AWS layers by executing `package-layer.sh`. This will make two files: `python3_layer_content.zip` and `mpic_coordinator_layer_content.zip` which will later be referenced by Open Tofu. This can be done by running `./package-layer.sh` or `hatch run lambda:layer-package`.
4. Run `configure.py` from the root directory of the repo to generate Open Tofu files from templates. This can be separately executed by running `hatch run ./configure.py` or `hatch run lambda:configure-tf`.
5. Zip all Lambda functions. AWS Lambda functions are usually deployed from zip files. This can be separately executed by running `./zip-all.sh` or `hatch run lambda:zip-all`.
5. Zip all Lambda functions. AWS Lambda functions are usually deployed from zip files. This can be separately executed by running `./zip-all.sh` or `hatch run lambda:zip-lambdas`.
6. Deploy the entire package with Open Tofu. cd to the `open-tofu` directory where .tf files are located. Then run `tofu init`. Then run `tofu apply` and type `yes` at the confirmation prompt. This provides a standard install with DNSSEC enabled which causes the system to incur expenses even when it is not in use (due to the AWS VPC NAT Gateways needed). To reduce the AWS bill, DNSSEC can also be disabled by appending `-var="dnssec_enabled=false"` to `tofu apply` (i.e., `tofu apply -var="dnssec_enabled=false"`).
7. Get the URL of the deployed API endpoint by running `hatch run ./get_api_url.py` in the root directory.
8. Get the API Key generated by AWS by running `hatch run ./get_api_key.py` in the root directory. The deployment is configured to reject any API call that does not have this key passed via the `x-api-key` HTTP header.
Expand Down Expand Up @@ -99,7 +99,7 @@ After `tofu destroy`, `./clean.sh` in the root directory also clears generated/z

## EventBridge Warmer

The AWS Lambda deployment takes approximately 8 seconds to perform the fist Open MPIC call because of [Lambda cold starts](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html). Subsequent calls take approximately 1 second. To avoid a cold start and get a ~1 second response time even on the first API call, the EventBridge Warmer can optionally be used to keep the Lambda functions "hot." To deploy with this feature, add `-var="eventbridge_warmer_enabled=true"` to the `tofu apply` command (e.g., `tofu apply -var="dnssec_enabled=false" -var="eventbridge_warmer_enabled=true"`). **The use of the EventBridge Warmer will increase costs and incur costs even when no API calls are being made.**
The AWS Lambda deployment takes approximately 8 seconds to perform the first Open MPIC call because of [Lambda cold starts](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html). Subsequent calls take approximately 1 second. To avoid a cold start and get a ~1 second response time even on the first API call, the EventBridge Warmer can optionally be used to keep the Lambda functions "hot." To deploy with this feature, add `-var="eventbridge_warmer_enabled=true"` to the `tofu apply` command (e.g., `tofu apply -var="dnssec_enabled=false" -var="eventbridge_warmer_enabled=true"`). **The use of the EventBridge Warmer will increase costs and incur costs even when no API calls are being made.**

## Additional Implementation Tasks
There are several features that may be of interest to the community, but we don't yet have a specific completion timeline. These may be given higher priority based on feedback and community interest.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ layer-install = "pip install . --upgrade --platform manylinux2014_aarch64 --only
layer-package = "./package-layer.sh"
configure-tf = "python configure.py"
zip-lambdas = "./zip-all.sh"
apply-tf-dnssec = "(cd open-tofu && tofu apply -var=\"dnssec_enabled=true\" -auto-approve)"
apply-tf-dnssec = "(cd open-tofu && tofu apply -var=\"dnssec_enabled=true\" -auto-approve)"
apply-tf-no-dnssec = "(cd open-tofu && tofu apply -var=\"dnssec_enabled=false\" -auto-approve)"
destroy-tf = "(cd open-tofu && tofu destroy -auto-approve)"
prepare = [
Expand Down
Loading