-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambdawrk2
executable file
·133 lines (115 loc) · 2.25 KB
/
lambdawrk2
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
#!/usr/bin/env bash
CUR_DIR=$(
cd $(dirname $0)
pwd
)
CDK_DIR="${CUR_DIR}/aws-cdk"
WRK2_CMD_DIR="${CUR_DIR}/wrk2-cmd"
WRK2_SCRIPT_DIR="${WRK2_CMD_DIR}/script"
# Default value
OUTPUT_DIR_PATH="${CUR_DIR}/output"
# Load env
if [[ -e "${CUR_DIR}/.env" ]]; then
export $(cat "${CUR_DIR}/.env" | grep -v ^# | xargs) >/dev/null
fi
function usage() {
cat <<EOF
usage: lambdawrk2 [command]
lambdawrk2 run wrk2 on AWS Lambda. Set options through environment variable. For more information, see $(.env.example).
Command:
setup create AWS resources, get wrk2 from GitHub
destroy cleanup AWS resources
run run wrk2
EOF
exit 0
}
# Setup CDK environment
function setupCdk() {
# Install node modules
if [[ ! -e "${CDK_DIR}/node_modules" ]]; then
cd "$CDK_DIR"
npm install
npm run build
cd "$CUR_DIR"
fi
}
# Setup Wrk2 environment
function setupWrk2() {
# Clone wrk2
if [[ ! -e "${WRK2_CMD_DIR}/docker/wrk2" ]]; then
git clone git@github.com:giltene/wrk2.git "${WRK2_CMD_DIR}/docker/wrk2"
fi
# Install node modules
if [[ ! -e "${WRK2_SCRIPT_DIR}/node_modules" ]]; then
cd "$WRK2_SCRIPT_DIR"
npm install
cd "$CUR_DIR"
fi
}
# setup command
function setup() {
setupWrk2
setupCdk
# Create AWS resources
cd "$CDK_DIR"
cdk deploy
}
# destroy command
function destroy() {
setupCdk
# Destroy AWS resources
cd "$CDK_DIR"
cdk destroy
}
# run command
function run() {
# Run
cd "$WRK2_SCRIPT_DIR"
npm run build
npm run start \
--aws_stackname="$AWS_STACK_NAME" \
--aws_profile="$AWS_PROFILE" \
--aws_region="$AWS_DEFAULT_REGION" \
--aws_key="$AWS_ACCESS_KEY_ID" \
--aws_secret="$AWS_SECRET_ACCESS_KEY" \
--parallel="$PARALLEL_COUNT" \
--wrk2_thread="$WRK2_THREAD" \
--wrk2_connection="$WRK2_CONNECTION" \
--wrk2_duration="$WRK2_DURATION" \
--wrk2_request_per_sec="$WRK2_REQUEST_PER_SEC" \
--wrk2_timeout="$WRK2_TIMEOUT" \
--wrk2_url="$WRK2_URL" \
--wrk2_script_path="$WRK2_SCRIPT_PATH" \
--output_dir_path="$OUTPUT_DIR_PATH"
}
# Parse commands and arguments.
CMD='usage'
for OPT in "$@"; do
case "$OPT" in
setup)
CMD='setup'
;;
destroy)
CMD='destroy'
;;
run)
CMD='run'
;;
esac
shift
done
# Run command.
case "$CMD" in
usage)
usage
;;
setup)
setup
;;
destroy)
destroy
;;
run)
run
;;
esac