-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-test.sh
47 lines (39 loc) · 1.19 KB
/
2-test.sh
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
#!/bin/bash
set -eo pipefail
cd $(dirname $0) && cd ..
DIR_REPO_ROOT=$(pwd)
DIR_SCRIPTs="${DIR_REPO_ROOT}/scripts"
DIR_TEST_EVENTS="${DIR_REPO_ROOT}/test-events"
DIR_SAM_CONFIG="${DIR_REPO_ROOT}/sam-config"
declare -A lambdaFns
function prepareLambdaFnsList {
templateFile=$1
#grep -E "FunctionName|Handler" ${templateFile} | while IFS= read -r line
## http://mywiki.wooledge.org/BashFAQ/024
while IFS= read -r line
do
if [[ ${line} =~ "FunctionName" ]]
then
function=$(echo ${line} | cut -d ' ' -f 2)
else
handler=$(echo ${line} | cut -d '/' -f 2 | cut -d '.' -f 1)
lambdaFns["${function}"]="${handler}"
fi
done <<< $(grep -E "FunctionName|Handler" ${templateFile})
}
function testLambda {
fnSource=${lambdaFns[$1]}
responseFile="${DIR_TEST_EVENTS}/${fnSource}-response.json"
payload=$(< ${DIR_TEST_EVENTS}/${fnSource}-test-event.json)
aws lambda invoke --function-name $1 \
${responseFile} \
--cli-binary-format raw-in-base64-out \
--payload "${payload}"
}
prepareLambdaFnsList ${DIR_SAM_CONFIG}/template.yml
while true
do
echo "Lambda functions: ${!lambdaFns[@]}"
read -p "Choose a lambda function: " lambdaFn
testLambda ${lambdaFn}
done