Skip to content

Commit 36ad19b

Browse files
committed
Add lambda dockerfile and deployment workflow
1 parent a87f13d commit 36ad19b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

.github/workflows/deploy-lambda.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Deploy Python Lambda
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
paths: ['src/backend/**']
7+
workflow_dispatch:
8+
9+
env:
10+
AWS_REGION: us-east-2
11+
ECR_REPOSITORY: mdst/mini-copilot
12+
CONTAINER_NAME: mini-copilot
13+
LAMBDA_FUNCTION_NAME: mini-copilot-lambda
14+
15+
jobs:
16+
deploy:
17+
name: Deploy
18+
runs-on: ubuntu-latest
19+
environment: production
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Configure AWS credentials
26+
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
27+
with:
28+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
aws-region: ${{ env.AWS_REGION }}
31+
32+
- name: Login to Amazon ECR
33+
id: login-ecr
34+
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
35+
36+
- name: Build, tag, and push image to Amazon ECR
37+
id: build-image
38+
working-directory: ./src/backend
39+
env:
40+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
41+
IMAGE_TAG: ${{ github.sha }}
42+
run: |
43+
# Build a docker container and push it to ECR
44+
aws s3 cp s3://mini-copilot/trained/ ./trained --recursive
45+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
46+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
47+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
48+
49+
- name: Update Lambda Function
50+
run: |
51+
aws lambda update-function-code --function-name ${{ env.LAMBDA_FUNCTION_NAME }} \
52+
--region ${{ env.AWS_REGION }} \
53+
--image-uri ${{ steps.build-image.outputs.image }}

src/backend/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM public.ecr.aws/lambda/python:3.12
2+
3+
# Copy requirements.txt
4+
COPY lambda_requirements.txt ${LAMBDA_TASK_ROOT}
5+
6+
# Install the specified packages
7+
RUN pip install --compile --no-cache-dir -r lambda_requirements.txt
8+
9+
# Copy model
10+
COPY trained/gpt2-728 ${LAMBDA_TASK_ROOT}/trained/gpt2-728
11+
12+
# Copy function code
13+
COPY lambda.py ${LAMBDA_TASK_ROOT}
14+
15+
# Set the CMD to your handler
16+
CMD [ "lambda.handler" ]

src/backend/lambda_requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
boto3
2+
torch
3+
transformers

0 commit comments

Comments
 (0)