-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (75 loc) · 2.79 KB
/
deploy-lambda.yml
File metadata and controls
83 lines (75 loc) · 2.79 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
79
80
81
82
83
name: Deploy Lambda Function
on:
release:
types: [published]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
FUNCTION_NAME: ${{ secrets.LAMBDA_FUNCTION_NAME }}
permissions:
id-token: write
contents: read
packages: read
jobs:
deploy:
if: ${{ github.event.release.target_commitish == 'master' }}
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build project
run: dotnet build --configuration Release
- name: Install Amazon Lambda Tools
run: dotnet tool install -g Amazon.Lambda.Tools
- name: Package Lambda function
working-directory: ${{ github.workspace }}/src/DispenserProvider
run: dotnet lambda package --configuration Release --output-package ../deployment.zip
- name: Upload deployment artifact
uses: actions/upload-artifact@v4
with:
name: lambda-deployment
path: src/deployment.zip
- name: Download deployment artifact
uses: actions/download-artifact@v4
with:
name: lambda-deployment
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy Lambda Code
run: |
aws lambda update-function-code --function-name "$FUNCTION_NAME" --zip-file fileb://deployment.zip > /dev/null 2>&1
- name: Wait for Lambda update to complete
run: |
echo "Waiting for Lambda function update to complete..."
attempt=0
max_attempts=30
while true; do
status=$(aws lambda get-function-configuration --function-name "$FUNCTION_NAME" --query 'LastUpdateStatus' --output text)
echo "Current status: $status"
if [ "$status" != "InProgress" ]; then
if [ "$status" = "Successful" ]; then
echo "Lambda function update completed successfully."
break
else
echo "Lambda function update finished with status: $status"
exit 1
fi
fi
sleep 1
attempt=$((attempt + 1))
if [ $attempt -ge $max_attempts ]; then
echo "Max attempts reached. Exiting."
exit 1
fi
done
- name: Update Lambda Description with Release URL
env:
RELEASE_URL: ${{ github.event.release.html_url }}
run: |
aws lambda update-function-configuration --function-name "$FUNCTION_NAME" --description "$RELEASE_URL" > /dev/null 2>&1