-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoke.sh
More file actions
executable file
·59 lines (51 loc) · 1.23 KB
/
invoke.sh
File metadata and controls
executable file
·59 lines (51 loc) · 1.23 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
#!/usr/bin/env bash
set -euo pipefail
FUNCTION_NAME="ai-latencies"
REGION="${AWS_REGION:-us-east-1}"
# Build the Lambda event payload from args
# Usage: ./invoke.sh [path] [querystring]
# Examples:
# ./invoke.sh /run "tests=llm:*&samples=2"
# ./invoke.sh /
# ./invoke.sh /teardown
PATH_ARG="${1:-/}"
QS="${2:-}"
METHOD="GET"
if [[ "$PATH_ARG" == "/teardown" ]]; then
METHOD="POST"
fi
PAYLOAD=$(jq -n \
--arg path "$PATH_ARG" \
--arg qs "$QS" \
--arg method "$METHOD" \
'{
rawPath: $path,
rawQueryString: $qs,
requestContext: {
http: { method: $method, path: $path },
requestId: "cli"
},
headers: {},
queryStringParameters: (
if $qs == "" then null
else ($qs | split("&") | map(split("=") | {(.[0]): .[1]}) | add)
end
)
}')
OUTFILE=$(mktemp)
trap 'rm -f "$OUTFILE"' EXIT
aws lambda invoke \
--function-name "$FUNCTION_NAME" \
--region "$REGION" \
--payload "$PAYLOAD" \
--cli-binary-format raw-in-base64-out \
--cli-read-timeout 300 \
--no-cli-pager \
"$OUTFILE" >/dev/null 2>&1
# Output: if CSV format, print raw; otherwise pretty-print JSON
BODY=$(jq -r '.body' "$OUTFILE")
if [[ "$QS" == *"format=csv"* ]]; then
echo "$BODY"
else
echo "$BODY" | jq .
fi