-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (66 loc) · 2.38 KB
/
Copy pathmain.yml
File metadata and controls
78 lines (66 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Deploy Lambda Function
on:
push:
branches:
- main
env:
AWS_REGION: eu-west-1
LAMBDA_FUNCTION_NAME: OsrsProgressLambda
AWS_ROLE_TO_ASSUME: arn:aws:iam::491234348360:role/group-ironman-lambda-role
permissions:
id-token: write
contents: read
jobs:
deploy:
name: Deploy Lambda
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install test dependencies
run: |
pip install awscli pytest requests discord-webhook
- name: Run unit tests
run: |
python -m unittest discover -s ./tests -p 'test_*.py'
- name: Install Lambda dependencies and package
run: |
mkdir -p lambda_package
pip install --target=lambda_package discord-webhook requests
cp lambda_function.py lambda_package/
cd lambda_package
zip -r ../function.zip .
cd ..
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
role-session-name: GitHubActionsLambdaDeployment
- name: Check if Lambda function exists
id: check_lambda
run: |
if aws lambda get-function --function-name ${{ env.LAMBDA_FUNCTION_NAME }} > /dev/null 2>&1; then
echo "lambda_exists=true" >> $GITHUB_OUTPUT
else
echo "lambda_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create or Update Lambda function
run: |
if [ "${{ steps.check_lambda.outputs.lambda_exists }}" == "false" ]; then
echo "Creating Lambda function..."
aws lambda create-function --function-name ${{ env.LAMBDA_FUNCTION_NAME }} > /dev/null \
--runtime python3.12 --role ${{ env.AWS_ROLE_TO_ASSUME }} \
--handler lambda_function.lambda_handler --zip-file fileb://function.zip
else
echo "Updating Lambda function..."
aws lambda update-function-code > /dev/null \
--function-name ${{ env.LAMBDA_FUNCTION_NAME }} \
--zip-file fileb://function.zip --publish
fi
- name: Clean up
run: rm -rf function.zip lambda_package