-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from dag-hammarskjold-library/lambda
Add Lambda function and GitHub Action to deploy
- Loading branch information
Showing
10 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
deploy Lambda function: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.10 | ||
- name: Setting up AWS Credentials | ||
run: | | ||
pip install awscli | ||
aws configure set region us-east-1 | ||
aws configure set output json | ||
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY}} | ||
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_KEY}} | ||
- name: Create virtual environment | ||
working-directory: ./aws-lambda | ||
run: | | ||
pip install virtualenv | ||
python3 -m virtualenv venv | ||
- name: Install requiremenents | ||
working-directory: ./aws-lambda | ||
run: | | ||
. venv/bin/activate | ||
python3 -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
deactivate | ||
- name: Deploy | ||
working-directory: ./aws-lambda | ||
run: | | ||
. venv/bin/activate | ||
lambda deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
venv/ | ||
env/ | ||
__pycache__/ | ||
*.py[co] | ||
.vscode | ||
_build/ | ||
/docs/_build/ | ||
.DS_Store | ||
.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
### About | ||
|
||
This is a Lambda function for running dlx-dl-sync. | ||
|
||
### Deployment | ||
|
||
This describes how to deploy this function to AWS Lambda using the Python library [python-lambda](https://pypi.org/project/python-lambda/). The files in this directory are the standard files necessary for deploying Python code to Lambda. | ||
|
||
AWS credentials must be configured in the deployment environment. | ||
|
||
1. Navigate to this directory (`dlx-dl/aws-lambda`) | ||
2. Make sure a virtual environment (venv) is activated. | ||
3. ```pip install -r requirements.txt``` | ||
4. ```lambda deploy``` | ||
|
||
Note that once the Lambda function is deployed, it will not run until it is "invoked". [Several methods exist to invoke the function](https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html). | ||
|
||
### Running the Lambda function locally (for development/testing purposes) | ||
|
||
```lambda invoke -v --event-file=bib-event.json``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"source": "dlx-dl-lambda", | ||
"type": "auth", | ||
"modified_within": 86400 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"source": "dlx-dl-lambda", | ||
"type": "bib", | ||
"modified_within": 86400 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
region: us-east-1 | ||
|
||
function_name: dlx-dl | ||
handler: service.handler | ||
description: DLX-DL Periodic Task Runner | ||
runtime: python3.8 | ||
role: service-role/dlx-dl-role-ggxqj9bh | ||
timeout: 900 | ||
|
||
# Build options | ||
build: | ||
source_directories: lib # a comma delimited list of directories in your project root that contains source to package. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
../. # installs dlx-dl from the directory above | ||
python-lambda @ git+https://github.com/nficano/python-lambda@2f9f17a5c5993e65ee2b61d06f29ed5a6689d337 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import json | ||
from dlx_dl.scripts import sync | ||
|
||
def handler(event, context): | ||
# event dict should contain the params expected by dlx.scripts.sync | ||
|
||
print(f'running with args: {json.dumps(event)}') | ||
|
||
try: | ||
sync.run(**event) | ||
except Exception as exc: | ||
print('; '.join(str(exc).split('\n'))) # puts exception text on one line for CloudWatch logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters