-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (95 loc) · 2.87 KB
/
Copy pathdeploy-lambda-function.yml
File metadata and controls
118 lines (95 loc) · 2.87 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Deploy WebDAV Lambda
on:
push:
branches:
- prod
paths:
- "infra/handler_webdav/**"
- ".github/workflows/deploy-lambda-function.yml"
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
AWS_REGION: us-east-2
LAMBDA_NAME: webdav-server-prod-handler
HANDLER_DIR: infra/handler_webdav
jobs:
deploy:
name: Build and deploy WebDAV
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ vars.AWS_LAMBDA_ROLE_TO_ASSUME_PROD }}
aws-region: ${{ env.AWS_REGION }}
role-session-name: gha-webdav-lambda-deploy
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: infra/handler_webdav/go.mod
cache: true
cache-dependency-path: infra/handler_webdav/go.sum
- name: Download and verify dependencies
working-directory: ${{ env.HANDLER_DIR }}
run: |
set -euo pipefail
go mod download
go mod verify
- name: Test handler
working-directory: ${{ env.HANDLER_DIR }}
run: |
set -euo pipefail
go test ./...
- name: Build Lambda bootstrap
working-directory: ${{ env.HANDLER_DIR }}
env:
GOOS: linux
GOARCH: arm64
CGO_ENABLED: "0"
run: |
set -euo pipefail
rm -rf dist
mkdir -p dist
go build \
-trimpath \
-ldflags="-s -w" \
-o dist/bootstrap \
.
chmod +x dist/bootstrap
file dist/bootstrap
- name: Package Lambda
working-directory: ${{ env.HANDLER_DIR }}
run: |
set -euo pipefail
cd dist
zip -j webdav-handler.zip bootstrap
unzip -l webdav-handler.zip
- name: Deploy Lambda
working-directory: ${{ env.HANDLER_DIR }}
run: |
set -euo pipefail
aws lambda update-function-code \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_NAME}" \
--zip-file fileb://dist/webdav-handler.zip
aws lambda wait function-updated \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_NAME}"
- name: Confirm deployed function
run: |
set -euo pipefail
aws lambda get-function-configuration \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_NAME}" \
--query '{
FunctionName:FunctionName,
Runtime:Runtime,
Architecture:Architectures[0],
LastModified:LastModified,
State:State,
LastUpdateStatus:LastUpdateStatus
}'