Skip to content

Commit

Permalink
Merge pull request #116 from dag-hammarskjold-library/docker-and-lambda
Browse files Browse the repository at this point in the history
dockerize, push to ECR, and update lambda
  • Loading branch information
aaronhelton authored May 30, 2024
2 parents 7ea8fa4 + e5ed791 commit d515004
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 53 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/deploy-lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and push container to ECR and Lambda
on:
release:
types: [ released ]

jobs:
deploy:
name: Build Docker and Deploy Lambda
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push the image to ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.REPO_NAME }}
IMAGE_TAG: latest
run: |
cd ./aws-lambda
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Deploy image to Lambda
id: deploy-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.REPO_NAME }}
IMAGE_TAG: latest
run: |
aws lambda update-function-code \
--function-name dlx-dl-lambda \
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Update EventBridge Rules
id: update-rules
run: |
aws events put-rule \
--name dlx-dl-lambda-bib \
--schedule-expression "rate(10 minutes)"
aws events put-targets \
--rule dlx-dl-lambda-bib \
--targets '[{"Id":"1","Arn":"${{ secrets.FUNCTION_ARN }}","Input":"{\"source\":\"dlx-dl-lambda\",\"type\":\"bib\",\"modified_within\":86400,\"queue\":true}"}]'
aws events put-rule \
--name dlx-dl-lambda-auth \
--schedule-expression "rate(10 minutes)"
aws events put-targets \
--rule dlx-dl-lambda-auth \
--targets '[{"Id":"1","Arn":"${{ secrets.FUNCTION_ARN }}","Input":"{\"source\":\"dlx-dl-lambda\",\"type\":\"auth\",\"modified_within\":86400,\"queue\":true}"}]'
37 changes: 0 additions & 37 deletions .github/workflows/deploy.yml

This file was deleted.

16 changes: 16 additions & 0 deletions aws-lambda/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM public.ecr.aws/lambda/python:3.11

# Copy requirements.txt
COPY requirements.txt ${LAMBDA_TASK_ROOT}

# Install git
RUN yum install -y git-all

# Install the specified packages
RUN pip install -r requirements.txt

# Copy function code
COPY service.py ${LAMBDA_TASK_ROOT}

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "service.handler" ]
2 changes: 2 additions & 0 deletions aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is a Lambda function for running dlx-dl-sync.

### Deployment

To do: Update this, since it's not relevant anymore

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.
Expand Down
13 changes: 0 additions & 13 deletions aws-lambda/config.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions aws-lambda/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
../. # installs dlx-dl from the directory above
python-lambda @ git+https://github.com/nficano/python-lambda@2f9f17a5c5993e65ee2b61d06f29ed5a6689d337
dlx-dl @ git+https://github.com/dag-hammarskjold-library/dlx-dl
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name = 'dlx_dl',
version = '1.2.3',
version = '1.2.4',
url = 'http://github.com/dag-hammarskjold-library/dlx-dl',
author = 'United Nations Dag Hammarskjöld Library',
author_email = '[email protected]',
Expand Down

0 comments on commit d515004

Please sign in to comment.