├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── aws-ab-util └── images ├── aws-ab-command-execution.png ├── aws-ab-command-output.png └── aws-ab-load-test.png /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## AWS AB Util 3 | 4 | AWS AB Util is a CLI utility tool to manage the deployment and execution of distributed load test with AB (Apache Bench) using AWS SSM and Amazon EC2. It can generate thousands of RPS (Requests per Second) and/or Gigabytes per second of data transfer. 5 | 6 | ## Requirements 7 | - OS: Linux, MacOS 8 | - Software: [AWS CLI](https://aws.amazon.com/cli/) 9 | - AWS CLI with permissions to execute AWS SSM Run Command and Amazon EC2 Admin Access 10 | - AWS IAM Role named **SSMInstanceProfile** as described in the SSM [documentation](https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-instance-profile.html#instance-profile-add-permissions) 11 | 12 | ## Install 13 | ``` 14 | git clone https://github.com/aws-samples/aws-ab-util.git 15 | sudo mv aws-ab-util/aws-ab-util /usr/local/bin/ 16 | rm -fr aws-ab-util 17 | ``` 18 | 19 | ## Usage 20 | Overall options. 21 | ``` 22 | # aws-ab-util 23 | Usage: aws-ab-util [parameters] 24 | cmd "[command]" 25 | create servers_count 26 | delete 27 | run [ab-options] [http[s]://]hostname[:port]/[path] 28 | ``` 29 | 30 | 31 | Creating 2x load test servers. 32 | ``` 33 | # aws-ab-util create 2 34 | Creating Load Test Servers... 35 | ``` 36 | 37 | 38 | Running a load test with 100 requests, per thread, per server. This will result in 1.000 request (100 requests x 5 threads x 2 servers). 39 | ``` 40 | # aws-ab-util run -c 5 -n 100 https://www.amazon.com/ 41 | Sending SSM Command... 42 | Running Load Test... 43 | Status: Success Success 44 | Detail: https://console.aws.amazon.com/systems-manager/run-command/00000000-1111-2222-3333-444444444444 45 | ``` 46 | 47 | Deleting servers 48 | ``` 49 | # aws-ab-util delete 50 | Deleting Load Test Servers... 51 | ``` 52 | 53 | Executing a command to create a JSON file 54 | ``` 55 | aws-ab-util cmd "echo '{\"message\":\"hello world\"}' > /tmp/payload.json" 56 | ``` 57 | 58 | ## SSM Run Command View 59 | ![SSM Command Execution](images/aws-ab-command-execution.png) 60 | 61 | ![SSM Command Output](images/aws-ab-command-output.png) 62 | 63 | ## Load Test Results Example 64 | ![Load test results example](images/aws-ab-load-test.png) 65 | 66 | ## Uninstall 67 | ``` 68 | sudo rm /usr/local/bin/aws-ab-util 69 | ``` 70 | 71 | ## Troubleshooting 72 | Error: Invalid IAM Instance Profile name 73 | 74 | Resolution: Create an IAM Role named **SSMInstanceProfile**, trusting in **EC2** entity, with **AmazonSSMManagedInstanceCore** policy attached [(documentation)](https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-instance-profile.html#instance-profile-add-permissions). 75 | 76 | 77 | ## Security 78 | 79 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. 80 | 81 | ## License 82 | 83 | This library is licensed under the MIT-0 License. See the LICENSE file. 84 | -------------------------------------------------------------------------------- /aws-ab-util: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INSTANCE_TYPE=t3a.small 4 | 5 | ROLE=SSMInstanceProfile 6 | USER_DATA="#!/bin/bash\nsudo yum install -y httpd" 7 | NAME="AB Load Test" 8 | 9 | get_ami_id() { 10 | aws ssm get-parameters \ 11 | --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 \ 12 | --query 'Parameters[0].[Value]' \ 13 | --output text 14 | } 15 | 16 | # Workaround to support commands using quotes 17 | # https://github.com/aws/aws-cli/issues/5080 18 | create_payload_file() { 19 | cmd=$1 20 | escaped_cmd=${cmd//\"/\\\"} # re-escape double quotes 21 | file=`mktemp /tmp/ab-util.XXXX` || exit 1 22 | echo "{\"Parameters\":{\"commands\":[\"${escaped_cmd}\"]}}" > ${file} 23 | echo $file 24 | } 25 | 26 | quote_items() { 27 | items=("$@") 28 | quoted_items= 29 | for item in "${items[@]}" 30 | do 31 | quoted_items+=" '${item}'" 32 | done 33 | echo ${quoted_items} 34 | } 35 | 36 | ssm_send_command() { 37 | cmd=$1 38 | file=$(create_payload_file "${cmd}") 39 | id=$(aws ssm send-command \ 40 | --document-name "AWS-RunShellScript" \ 41 | --targets "Key=tag:Name,Values=${NAME}" \ 42 | --query "Command.CommandId" \ 43 | --cli-input-json file://${file} \ 44 | --output text) 45 | rm $file 46 | echo ${id} 47 | } 48 | 49 | status() { 50 | id=$1 51 | while true; do 52 | status=$(aws ssm list-command-invocations \ 53 | --command-id $id \ 54 | --query "CommandInvocations[*].Status" \ 55 | --output text) 56 | 57 | if [[ ! "$status" =~ "InProgress" ]]; then 58 | echo -e "\nStatus: $status" 59 | echo "Detail: https://console.aws.amazon.com/systems-manager/run-command/$id" 60 | break 61 | fi 62 | echo -n . 63 | sleep 2 64 | done 65 | } 66 | 67 | create() { 68 | echo "Creating Load Test Servers..." 69 | count=$1 70 | ami_id=$(get_ami_id) 71 | aws ec2 run-instances \ 72 | --image-id ${ami_id} \ 73 | --instance-type ${INSTANCE_TYPE} \ 74 | --count ${count} \ 75 | --associate-public-ip-address \ 76 | --iam-instance-profile Name=${ROLE} \ 77 | --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$NAME}]" \ 78 | --user-data "$(echo -e ${USER_DATA})" > /dev/null 79 | } 80 | 81 | delete() { 82 | echo "Deleting Load Test Servers..." 83 | instances=$(aws ec2 describe-instances \ 84 | --filters "Name=tag:Name,Values=${NAME}" "Name=instance-state-name,Values=running" \ 85 | --query "Reservations[*].Instances[*].{Instance:InstanceId}" \ 86 | --output text) 87 | aws ec2 terminate-instances --instance-ids ${instances} > /dev/null 88 | } 89 | 90 | cmd() { 91 | echo "Sending SSM Command..." 92 | cmd=$1 93 | id=$(ssm_send_command "${cmd}") 94 | echo -n "Executing Command" 95 | status $id 96 | } 97 | 98 | run() { 99 | echo "Sending SSM Command..." 100 | args=("$@") 101 | quoted_args=$(quote_items "${args[@]}") 102 | cmd="ab ${quoted_args}" 103 | id=$(ssm_send_command "${cmd}") 104 | echo -n "Running Load Test" 105 | status $id 106 | } 107 | 108 | case "$1" in 109 | create) 110 | count=$2 111 | create $count 112 | ;; 113 | delete) 114 | delete 115 | ;; 116 | run) 117 | args=("${@:2}") 118 | run "${args[@]}" 119 | ;; 120 | cmd) 121 | cmd=${@:2} 122 | cmd "${cmd}" 123 | ;; 124 | *) 125 | echo "Usage: aws-ab-util [parameters]" 126 | echo " cmd \"[command]\"" 127 | echo " create servers_count" 128 | echo " delete" 129 | echo " run [ab-options] [http[s]://]hostname[:port]/[path]" 130 | RETVAL=2 131 | esac 132 | 133 | exit $RETVAL 134 | -------------------------------------------------------------------------------- /images/aws-ab-command-execution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-ab-util/9823617b7f1cb4ca2e35c1c950de95efab25f9e0/images/aws-ab-command-execution.png -------------------------------------------------------------------------------- /images/aws-ab-command-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-ab-util/9823617b7f1cb4ca2e35c1c950de95efab25f9e0/images/aws-ab-command-output.png -------------------------------------------------------------------------------- /images/aws-ab-load-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-ab-util/9823617b7f1cb4ca2e35c1c950de95efab25f9e0/images/aws-ab-load-test.png --------------------------------------------------------------------------------