Skip to content

Commit 2af2a67

Browse files
Add deploy lambda fetch job
1 parent b17456f commit 2af2a67

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on:
88

99
permissions:
1010
contents: read
11+
id-token: write
1112

1213
jobs:
1314
test:
14-
1515
runs-on: ubuntu-latest
1616

1717
steps:
@@ -47,3 +47,55 @@ jobs:
4747
with:
4848
name: test-report
4949
path: test-reports/report.html
50+
51+
deploy_lambda_fetch:
52+
needs: test
53+
if: ${{ needs.test.result == 'success' }}
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout
57+
uses: actions/checkout@v4
58+
59+
- name: Check for code changes
60+
id: changes_fetch
61+
run: |
62+
echo "changed=false" >> $GITHUB_OUTPUT
63+
if git diff --name-only HEAD^ HEAD | grep -q '^lambda_fetch/'; then
64+
echo "changed=true" >> $GITHUB_OUTPUT
65+
fi
66+
67+
- name: Configure AWS credentials
68+
if: steps.changes_fetch.outputs.changed == 'true'
69+
uses: aws-actions/configure-aws-credentials@v3
70+
with:
71+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
72+
aws-region: ${{ secrets.AWS_REGION }}
73+
74+
- name: Log in to Amazon ECR
75+
if: steps.changes_fetch.outputs.changed == 'true'
76+
uses: aws-actions/amazon-ecr-login@v2
77+
78+
- name: Build, tag, and push Docker image to ECR
79+
if: steps.changes_fetch.outputs.changed == 'true'
80+
run: |
81+
IMAGE_TAG=latest
82+
ECR_REGISTRY=$(aws sts get-caller-identity --query "Account" --output text).dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
83+
ECR_REPOSITORY=predictit-fetch
84+
docker buildx build --platform linux/amd64 --provenance=false \
85+
-t $ECR_REPOSITORY:$IMAGE_TAG \
86+
-f ./lambda_fetch/Dockerfile .
87+
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
88+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
89+
90+
- name: Update Lambda function
91+
if: steps.changes_fetch.outputs.changed == 'true'
92+
run: |
93+
FUNCTION_NAME=predictit-fetch
94+
IMAGE_TAG=latest
95+
ECR_REGISTRY=$(aws sts get-caller-identity --query "Account" --output text).dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
96+
ECR_REPOSITORY=predictit-fetch
97+
98+
aws lambda update-function-code \
99+
--function-name $FUNCTION_NAME \
100+
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
101+
--region ${{ secrets.AWS_REGION }}

lambda_fetch/lambda_function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ def lambda_handler(event, context) -> Optional[dict]:
5252
except Exception as e:
5353
logger.error(f"Error occurred: {e}")
5454
raise
55+
56+
def _deployment_test_dummy():
57+
print('This is a dummy function to test the deployment pipeline')

0 commit comments

Comments
 (0)