Skip to content

Commit

Permalink
Initial commit of curl_for_latency script and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
defila-aws committed Dec 20, 2016
1 parent 2d3d53f commit f782f90
Showing 2 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions APIGateway/curl_for_latency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# curl_for_latency

*Bash script for checking latency when communicating with API Gateway through CloudFront.*

----

This script will execute three (3) requests to the endpoint at two (2) second intervals. The results show the total time taken for the request and response, and the time for each step. Descriptions are included for what is occurring.

## Requirements

* The script `curl_for_latency.sh` requires the following modifications.
* Replace the `method` and `URL` in the curl command
* *-X `GET` `"https://1234567890.execute-api.us-west-2.amazonaws.com/stage/resource?nocaching=$(uuidgen)"`*
* Optional: Add custom headers by including them below the verbose option `-v` as `-H 'header-key:value'`
57 changes: 57 additions & 0 deletions APIGateway/curl_for_latency/curl_for_latency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
# except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.


# Created by Andrew R. DeFilippis


# Read into a variable, the block of "curl timing output" text
read -r -d '' TIME_DATA << EOV
\n ---------Operation is beginning---------
url_effective : '%{url_effective}' <-- (The URL that was fetched last.)
http_code : %{http_code} <-- (The numerical response code that was found in the last retrieved HTTP(S) or FTP(s) transfer.)
content_type : '%{content_type}' <-- (The Content-Type of the requested document, if there was any.)\n
---------Local DNS resolution beginning---------
time_namelookup : %{time_namelookup} <-- (The time, in seconds, it took from the start until the DNS name resolution was completed.)\n
---------Connection to CloudFront beginning---------
time_connect : %{time_connect} <-- (The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)
time_appconnect : %{time_appconnect} <-- (The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.)\n
---------Communication between CloudFront and API Gateway (via Internet backbone networks) beginning---------
time_pretransfer : %{time_pretransfer} <-- (The time, in seconds, it took from the start until the file transfer was just about to begin.)
time_redirect : %{time_redirect} <-- (The time, in seconds, it took for all redirection steps before the final transaction was started.)\n
---------NOTE: Communication between API Gateway and the Integration Request Endpoint occurring---------
---------NOTE: Communication between API Gateway and CloudFront (via Internet backbone networks) occurring---------\n
---------Response from CloudFront beginning---------
time_starttransfer : %{time_starttransfer} <-- (The time, in seconds, it took from the start until the first byte was just about to be transferred.)
size_download : %{size_download} <-- (The total amount of bytes that were downloaded.)\n
---------Response has been received---------
time_total : %{time_total} <-- (The total time, in seconds, that the full operation lasted.)
---------Operation is complete---------\n
EOV


# Execute the curl command
# NOTE: The URL and curl options should be modified to suit your needs, including adding headers (API keys, Authorization tokens, etc.)
# The query string "nocaching=$(uuidgen)" is automatically populated with a random UUID. This can be used to prevent caching of the requests.
x=1
while (( x <= 3 )); do
sleep 2
echo "\n-----------------------------------\n"
curl \
-w "$TIME_DATA" \
-o /dev/null \
-s \
-v \
-X GET "https://1234567890.execute-api.us-west-2.amazonaws.com/stage/resource?nocaching=$(uuidgen)"
((x++))
done

0 comments on commit f782f90

Please sign in to comment.