generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 40
Lab Dragon Resort #1239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Lab Dragon Resort #1239
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "DragonResortApp": { | ||
| "DYNAMODB_ENDPOINT": "http://host.docker.internal:8000", | ||
| "DYNAMODB_TABLE_NAME": "DragonTable" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "httpMethod": "POST", | ||
| "path": "/", | ||
| "headers": {"Content-Type": "application/json"}, | ||
| "body": "{\"id\":\"11111111-2222-3333-4444-555555555555\",\"name\":\"Elliot\",\"type\":\"Forest Dragon\",\"age\":\"1200\",\"color\":\"green\"}" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "httpMethod": "DELETE", | ||
| "path": "/", | ||
| "headers": {"Content-Type": "application/json"}, | ||
| "pathParameters": {"id": "11111111-2222-3333-4444-555555555555"}, | ||
| "body": null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Get API endpoint from AWS CLI using API name for REST API (v1) | ||
| API_NAME="Dragon Store API" | ||
| REGION="eu-central-1" | ||
|
|
||
| # Get API ID from name (REST API) | ||
| API_ID=$(aws apigateway get-rest-apis --region $REGION | \ | ||
| jq -r --arg NAME "$API_NAME" '.items[] | select(.name==$NAME) | .id') | ||
|
|
||
| if [ -z "$API_ID" ]; then | ||
| echo "Failed to find REST API with name: $API_NAME" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Construct API endpoint for REST API | ||
| API_ENDPOINT="https://${API_ID}.execute-api.${REGION}.amazonaws.com/prod" | ||
|
|
||
| # Print API information for verification | ||
| echo "Found API ID: $API_ID" | ||
| echo "Using API endpoint: $API_ENDPOINT" | ||
|
|
||
| # Rest of the configuration | ||
| NUM_REQUESTS=100 | ||
| CONTENT_TYPE="Content-Type: application/json" | ||
|
|
||
| # Dragon characteristics arrays | ||
| FIRST_NAMES=("Ancient" "Mighty" "Wise" "Fierce" "Noble" "Shadow" "Storm" "Crystal" "Ember" "Frost") | ||
| SECOND_NAMES=("Wing" "Claw" "Fang" "Scale" "Heart" "Soul" "Spirit" "Flame" "Thunder" "Ice") | ||
| TYPES=("Celestial Dragon" "Fire Dragon" "Ice Dragon" "Storm Dragon" "Earth Dragon") | ||
| COLORS=("bronze" "golden" "silver" "crimson" "azure" "emerald" "obsidian") | ||
|
|
||
| # Function to get random element from an array | ||
| get_random_element() { | ||
| local array=("$@") | ||
| local index=$((RANDOM % ${#array[@]})) | ||
| echo "${array[$index]}" | ||
| } | ||
|
|
||
| # Function to generate random number in range | ||
| random_number() { | ||
| local min=$1 | ||
| local max=$2 | ||
| echo $((RANDOM % (max - min + 1) + min)) | ||
| } | ||
|
|
||
| # Function to make API calls with error handling and response logging | ||
| make_request() { | ||
| local method=$1 | ||
| local endpoint=$2 | ||
| local data=$3 | ||
|
|
||
| response=$(curl -s -w "\n%{http_code}" -X "$method" \ | ||
| "$API_ENDPOINT$endpoint" \ | ||
| -H "$CONTENT_TYPE" \ | ||
| ${data:+-d "$data"}) | ||
|
|
||
| status_code=$(echo "$response" | tail -n1) | ||
| response_body=$(echo "$response" | sed '$d') | ||
|
|
||
| if [ "$status_code" -lt 200 ] || [ "$status_code" -gt 299 ]; then | ||
| echo "Error: $method request to $endpoint failed with status $status_code" | ||
| echo "Response: $response_body" | ||
| fi | ||
| } | ||
|
|
||
| # Function to create dragon payload with random attributes | ||
| create_dragon_payload() { | ||
| local id=$1 | ||
| local first_name=$(get_random_element "${FIRST_NAMES[@]}") | ||
| local second_name=$(get_random_element "${SECOND_NAMES[@]}") | ||
| local dragon_type=$(get_random_element "${TYPES[@]}") | ||
| local color=$(get_random_element "${COLORS[@]}") | ||
| local age=$(random_number 100 5000) | ||
|
|
||
| echo "{ | ||
| \"id\": \"$id\", | ||
| \"name\": \"$first_name$second_name\", | ||
| \"type\": \"$dragon_type\", | ||
| \"age\": \"$age\", | ||
| \"color\": \"$color\" | ||
| }" | ||
| } | ||
|
|
||
| # Function to run batch of requests with progress indicator | ||
| run_batch() { | ||
| local operation=$1 | ||
| local total=$2 | ||
| local successful=0 | ||
| local failed=0 | ||
|
|
||
| echo "Starting $operation test..." | ||
| for ((i=1; i<=$total; i++)); do | ||
| echo -ne "Progress: $i/$total (Success: $successful, Failed: $failed)\r" | ||
|
|
||
| case $operation in | ||
| "CREATE") | ||
| make_request "POST" "/dragons" "$(create_dragon_payload $i)" | ||
| ;; | ||
| "LIST") | ||
| make_request "GET" "/dragons" | ||
| ;; | ||
| "GET") | ||
| make_request "GET" "/dragons/$i" | ||
| ;; | ||
| "DELETE") | ||
| make_request "DELETE" "/dragons/$i" | ||
| ;; | ||
| esac | ||
|
|
||
| if [ $? -eq 0 ]; then | ||
| ((successful++)) | ||
| else | ||
| ((failed++)) | ||
| fi | ||
|
|
||
| # Small delay to prevent overwhelming the API | ||
| sleep 0.1 | ||
| done | ||
| echo -e "\nCompleted $operation test (Success: $successful, Failed: $failed)" | ||
| } | ||
|
|
||
| # Main execution | ||
| echo "Starting load test at $(date)" | ||
| run_batch "CREATE" $NUM_REQUESTS | ||
| run_batch "LIST" $NUM_REQUESTS | ||
| run_batch "GET" $NUM_REQUESTS | ||
| run_batch "DELETE" $NUM_REQUESTS | ||
| echo "Load test completed at $(date)" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "httpMethod": "GET", | ||
| "path": "/", | ||
| "headers": {"Content-Type": "application/json"}, | ||
| "pathParameters": {"id": "11111111-2222-3333-4444-555555555555"}, | ||
| "body": null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "httpMethod": "GET", | ||
| "path": "/", | ||
| "headers": {"Content-Type": "application/json"}, | ||
| "body": null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "httpMethod": "PUT", | ||
| "path": "/", | ||
| "headers": {"Content-Type": "application/json"}, | ||
| "pathParameters": {"id": "11111111-2222-3333-4444-555555555555"}, | ||
| "body": "{\"name\":\"Elliot\",\"type\":\"Red Forest Dragon\",\"age\":\"1200\",\"color\":\"red\"}" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.