-
Notifications
You must be signed in to change notification settings - Fork 155
269 lines (235 loc) · 8.18 KB
/
Copy pathexamples.yaml
File metadata and controls
269 lines (235 loc) · 8.18 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
name: Verify Examples
on:
pull_request:
branches:
- main
paths:
- "examples/**"
push:
branches:
- main
paths:
- "src/**"
workflow_dispatch:
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
validate:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.13"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate all SAM templates
run: |
failed=0
for template in $(find examples -maxdepth 2 -name "template.yaml" | sort); do
dir=$(dirname "$template")
echo "Validating $dir..."
if ! sam validate --template "$template" --lint 2>&1; then
echo "FAIL: $dir"
failed=1
fi
done
if [ "$failed" -eq 1 ]; then
echo "Some templates failed validation"
exit 1
fi
build-layer:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
run: rustup target add x86_64-unknown-linux-musl
- name: Install cargo lambda
run: pip3 install cargo-lambda
- name: Configure Rust cache
uses: Swatinem/rust-cache@v2
- name: Build x86_64 layer
run: |
cargo lambda build --release --extension --target x86_64-unknown-linux-musl
mkdir -p layer-x86_64
cp layer/bootstrap layer-x86_64/
cp target/lambda/extensions/lambda-adapter layer-x86_64/
- uses: actions/upload-artifact@v4
with:
name: layer-x86_64
path: layer-x86_64/
# Docker-based examples verified with sam local start-api.
# Excluded: nginx, php, flask, aspnet-mvc (web app hardcodes port 8080
# which conflicts with SAM's Lambda Runtime Interface Emulator).
test-image:
needs: [build-layer]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
example:
- expressjs
- fastapi
- fastapi-background-tasks
- fasthtml
- gin
- nextjs
- remix
- springboot
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.13"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: layer-x86_64
path: /tmp/layer-x86_64
- name: Build local adapter image
run: |
chmod +x /tmp/layer-x86_64/lambda-adapter
printf 'FROM scratch\nCOPY --chmod=755 lambda-adapter /lambda-adapter\n' | \
docker build -t public.ecr.aws/awsguru/aws-lambda-adapter:1.0.0 -f- /tmp/layer-x86_64
- name: Build
working-directory: examples/${{ matrix.example }}
run: sam build
- name: Start local API and verify
working-directory: examples/${{ matrix.example }}
run: |
# Set PORT=8000 to avoid conflict with SAM's RIE on port 8080
echo '{"Parameters":{"PORT":"8000"}}' > /tmp/env.json
sam local start-api --port 3000 --warm-containers EAGER --container-env-vars /tmp/env.json &
SAM_PID=$!
echo "SAM_PID=$SAM_PID" >> $GITHUB_ENV
echo "Waiting for local API to start..."
for i in $(seq 1 90); do
if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:3000/ 2>/dev/null | grep -q "^[2345]"; then
echo "API is ready after ${i}s"
break
fi
if [ "$i" -eq 90 ]; then
echo "API failed to start within 90s"
kill $SAM_PID 2>/dev/null || true
exit 1
fi
sleep 1
done
status=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:3000/)
echo "HTTP status: $status"
if [[ "$status" -ge 200 && "$status" -lt 500 ]]; then
echo "OK: Got valid response"
else
echo "FAIL: Unexpected status $status"
kill $SAM_PID 2>/dev/null || true
exit 1
fi
- name: Stop local API
if: always()
run: kill $SAM_PID 2>/dev/null || true
# Zip-based examples verified with local layer.
# Excluded: aspnet-*-zip (hardcode port 8080),
# bun/nginx/php-zip (need third-party layers), arm64 examples (javalin, rust-*),
# nextjs-zip (Makefile produces a zip artifact incompatible with sam local).
test-zip:
needs: [build-layer]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
example:
- deno-zip
- expressjs-zip
- fastapi-zip
- fasthtml-zip
- flask-zip
- gin-zip
- remix-zip
- springboot-zip
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.13"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
token: ${{ secrets.GITHUB_TOKEN }}
- uses: denoland/setup-deno@v2
if: matrix.example == 'deno-zip'
with:
deno-version: v2.x
- uses: actions/download-artifact@v4
with:
name: layer-x86_64
path: /tmp/layer-x86_64
- name: Build
working-directory: examples/${{ matrix.example }}
run: sam build
- name: Inject local layer into build output
working-directory: examples/${{ matrix.example }}
run: |
# Prepare local layer directory with correct structure
LAYER_DIR=".aws-sam/build/LocalAdapterLayer"
mkdir -p "$LAYER_DIR/extensions"
cp /tmp/layer-x86_64/bootstrap "$LAYER_DIR/"
cp /tmp/layer-x86_64/lambda-adapter "$LAYER_DIR/extensions/"
chmod +x "$LAYER_DIR/bootstrap" "$LAYER_DIR/extensions/lambda-adapter"
# Add local layer resource and replace remote layer ARN refs
pip install pyyaml -q
python3 << 'PYEOF'
import yaml
with open(".aws-sam/build/template.yaml") as f:
t = yaml.safe_load(f)
t["Resources"]["LocalAdapterLayer"] = {
"Type": "AWS::Lambda::LayerVersion",
"Properties": {"Content": "LocalAdapterLayer", "LayerName": "local-adapter"},
}
for r in t.get("Resources", {}).values():
layers = r.get("Properties", {}).get("Layers", [])
for i, l in enumerate(layers):
if "LambdaAdapterLayerX86" in str(l):
layers[i] = {"Ref": "LocalAdapterLayer"}
with open(".aws-sam/build/template.yaml", "w") as f:
yaml.dump(t, f)
PYEOF
- name: Start local API and verify
working-directory: examples/${{ matrix.example }}
run: |
# Set PORT=8000 to avoid conflict with SAM's RIE on port 8080
echo '{"Parameters":{"PORT":"8000"}}' > /tmp/env.json
sam local start-api --port 3000 --warm-containers EAGER --container-env-vars /tmp/env.json &
SAM_PID=$!
echo "SAM_PID=$SAM_PID" >> $GITHUB_ENV
echo "Waiting for local API to start..."
for i in $(seq 1 90); do
if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:3000/ 2>/dev/null | grep -q "^[2345]"; then
echo "API is ready after ${i}s"
break
fi
if [ "$i" -eq 90 ]; then
echo "API failed to start within 90s"
kill $SAM_PID 2>/dev/null || true
exit 1
fi
sleep 1
done
status=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:3000/)
echo "HTTP status: $status"
if [[ "$status" -ge 200 && "$status" -lt 500 ]]; then
echo "OK: Got valid response"
else
echo "FAIL: Unexpected status $status"
kill $SAM_PID 2>/dev/null || true
exit 1
fi
- name: Stop local API
if: always()
run: kill $SAM_PID 2>/dev/null || true