@@ -34,10 +34,10 @@ locals {
3434
3535data "aws_ami" "ami" {
3636 owners = [" amazon" ]
37- most_recent = true
37+ most_recent = true
3838 filter {
3939 name = " name"
40- values = [" al20* -ami-minimal -*-${ var . cpu_architecture } " ]
40+ values = [" al2023 -ami-*-${ var . cpu_architecture } " ]
4141 }
4242 filter {
4343 name = " state"
@@ -47,21 +47,6 @@ data "aws_ami" "ami" {
4747 name = " architecture"
4848 values = [var . cpu_architecture ]
4949 }
50- filter {
51- name = " image-type"
52- values = [" machine" ]
53- }
54-
55- filter {
56- name = " root-device-name"
57- values = [" /dev/xvda" ]
58- }
59-
60- filter {
61- name = " root-device-type"
62- values = [" ebs" ]
63- }
64-
6550 filter {
6651 name = " virtualization-type"
6752 values = [" hvm" ]
@@ -129,17 +114,12 @@ cat > /app/generate_traffic.sh << 'TRAFFIC_EOF'
129114#!/bin/bash
130115
131116# Configuration
132- SERVER_URL="${ SERVER_URL : - http : // localhost : 8000 } "
133- ENDPOINT="${ SERVER_URL } /ai-chat"
134- DELAY_SECONDS="${ DELAY_SECONDS : - 3600 } "
135- NUM_REQUESTS="${ NUM_REQUESTS : - 0 } "
136- TIMEOUT="${ TIMEOUT : - 30 } "
117+ SERVER_URL="$$ {SERVER_URL:-http://localhost:8000}"
118+ ENDPOINT="$$ SERVER_URL/ai-chat"
119+ DELAY_SECONDS="$$ {DELAY_SECONDS:-3600}"
120+ NUM_REQUESTS="$$ {NUM_REQUESTS:-0}"
121+ TIMEOUT="$$ {TIMEOUT:-30}"
137122
138- # Color codes for output
139- GREEN='\033[0;32m'
140- RED='\033[0;31m'
141- YELLOW='\033[1;33m'
142- NC='\033[0m'
143123
144124# Array of sample messages
145125MESSAGES=(
@@ -162,78 +142,74 @@ MESSAGES=(
162142
163143# Function to send a request
164144send_request() {
165- local message="$1"
166- local request_num="$2"
167- local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
145+ local message="$$ 1"
146+ local request_num="$$ 2"
147+ local timestamp=$$ (date '+%Y-%m-%d %H:%M:%S')
168148
169- echo -e " ${ YELLOW } [$ timestamp] Request #$request_num ${ NC } "
170- echo "Message: \"$message\""
149+ echo "[$$ timestamp] Request #$$request_num "
150+ echo "Message: \"$$ message\""
171151
172- local trace_id_header="${ TRACE_ID : - Root = 1 - 5759e988 - bd862e3fe1be46a994272793 ; Parent =53995c3f42cd8ad8; Sampled = 1 } "
152+ local trace_id_header="$$ {TRACE_ID:-${ var . trace_id } }"
173153
174- echo "Using Trace ID: $trace_id_header"
154+ echo "Using Trace ID: $$ trace_id_header"
175155
176- response=$(curl -s -X POST "$ENDPOINT" \
156+ response=$$ (curl -s -X POST "$ $ENDPOINT" \
177157 -H "Content-Type: application/json" \
178- -H "X-Amzn-Trace-Id: $trace_id_header" \
179- -d "{\"message\": \"$message\"}" \
180- -m "$TIMEOUT" \
158+ -H "X-Amzn-Trace-Id: $$ trace_id_header" \
159+ -d "{\"message\": \"$$ message\"}" \
160+ -m "$$ TIMEOUT" \
181161 -w "\nHTTP_STATUS:%{ http_code } \nTIME_TOTAL:%{ time_total } ")
182162
183- http_status=$(echo "$response" | grep "HTTP_STATUS:" | cut -d: -f2)
184- time_total=$(echo "$response" | grep "TIME_TOTAL:" | cut -d: -f2)
185- body=$(echo "$response" | sed '/HTTP_STATUS:/d' | sed '/TIME_TOTAL:/d')
163+ http_status=$$ (echo "$ $response" | grep "HTTP_STATUS:" | cut -d: -f2)
164+ time_total=$$ (echo "$ $response" | grep "TIME_TOTAL:" | cut -d: -f2)
165+ body=$$ (echo "$ $response" | sed '/HTTP_STATUS:/d' | sed '/TIME_TOTAL:/d')
186166
187- if [ "$http_status" = "200" ]; then
188- echo -e " ${ GREEN } ✓ Success${ NC } ( ${ time_total } s)"
189- echo "Response: $body"
167+ if [ "$$ http_status" = "200" ]; then
168+ echo " Success ($ ${time_total}s)"
169+ echo "Response: $$ body"
190170 else
191- echo -e " ${ RED } ✗ Error: HTTP $http_status ${ NC } "
192- if [ -n "$body" ]; then
193- echo "Response: $body"
171+ echo " Error: HTTP $$http_status "
172+ if [ -n "$$ body" ]; then
173+ echo "Response: $$ body"
194174 fi
195175 fi
196176 echo "---"
197177}
198178
199- # Trap Ctrl+C to exit gracefully
200- trap 'echo -e "\n${ YELLOW } Traffic generation stopped by user${ NC } "; exit 0' INT
201-
202- echo -e "${ GREEN } Starting traffic generation to $ENDPOINT${ NC } "
179+ echo "Starting traffic generation to $$ENDPOINT"
203180echo "Configuration:"
204- echo " - Delay between requests: ${ DELAY_SECONDS } s"
205- echo " - Request timeout: ${ TIMEOUT } s"
206- echo " - Number of requests: ${ NUM_REQUESTS } (0 = infinite)"
207- echo " - Requests per minute: ~$((60 / DELAY_SECONDS))"
208- echo -e "${ YELLOW } Press Ctrl+C to stop${ NC } "
181+ echo " - Delay between requests: $${DELAY_SECONDS}s"
182+ echo " - Request timeout: $${TIMEOUT}s"
183+ echo " - Number of requests: $${NUM_REQUESTS} (0 = infinite)"
184+ echo " - Requests per minute: ~$$((60 / DELAY_SECONDS))"
209185echo "=================================="
210186
211187count=0
212- start_time=$(date +%s)
188+ start_time=$$ (date +%s)
213189
214190while true; do
215- random_index=$((RANDOM % ${ #MESSAGES [@]} ))
216- message="${ MESSAGES [$random_index ]} "
191+ random_index=$$ ((RANDOM % $ ${#MESSAGES[@]}))
192+ message="$$ {MESSAGES[$ $random_index]}"
217193
218- count=$((count + 1))
194+ count=$$ ((count + 1))
219195
220- send_request "$message" "$count"
196+ send_request "$$ message" "$ $count"
221197
222- if [ "$NUM_REQUESTS" -gt 0 ] && [ "$count" -ge "$NUM_REQUESTS" ]; then
223- end_time=$(date +%s)
224- duration=$((end_time - start_time))
225- echo -e " ${ GREEN } Completed $count requests in ${ duration } s${ NC } "
198+ if [ "$$ NUM_REQUESTS" -gt 0 ] && [ "$$ count" -ge "$ $NUM_REQUESTS" ]; then
199+ end_time=$$ (date +%s)
200+ duration=$$ ((end_time - start_time))
201+ echo " Completed $$ count requests in $$ {duration}s"
226202 break
227203 fi
228204
229- if [ $((count % 10)) -eq 0 ]; then
230- current_time=$(date +%s)
231- elapsed=$((current_time - start_time))
232- rate=$(echo "scale=2; $count / $elapsed * 60" | bc 2>/dev/null || echo "N/A")
233- echo -e " ${ YELLOW } Progress: $count requests sent, Rate: ${ rate } req/min${ NC } "
205+ if [ $$ ((count % 10)) -eq 0 ]; then
206+ current_time=$$ (date +%s)
207+ elapsed=$$ ((current_time - start_time))
208+ rate=$$ (echo "scale=2; $$ count / $ $elapsed * 60" | bc 2>/dev/null || echo "N/A")
209+ echo " Progress: $$ count requests sent, Rate: $$ {rate} req/min"
234210 fi
235211
236- sleep "$DELAY_SECONDS"
212+ sleep "$$ DELAY_SECONDS"
237213done
238214TRAFFIC_EOF
239215
0 commit comments