This sample application uses the Locust open source load testing tool to create a simple load generator for your applications. The sample test definition locustfile.py tests the root of an endpoint passed in as an environment variable (TARGET_URL). For more information on the format of the test definition file, see Writing a locustfile.
You can get started using the following steps:
- Install the AWS Elastic Beanstalk Command Line Interface (CLI).
- Create an IAM Instance Profile named aws-elasticbeanstalk-locust-role with the policy in policy.json. For more information on how to create an IAM Instance Profile, see Create an IAM Instance Profile for Your Amazon EC2 Instances.
- Run
eb init -r <region> -p "Java 8"
to initialize the folder for use with the CLI. Replace<region>
with a region identifier such asus-west-2
(see Regions and Endpoints for a full list of region identifiers). For interactive mode, runeb init
then,- Pick a region of your choice.
- Select the [ Create New Application ] option.
- Enter the application name of your choice.
- Answer no to It appears you are using Python. Is this correct?.
- Select Java as the platform.
- Select Java 8 as the platform version.
- Choose whether you want SSH access to the Amazon EC2 instances.
Note: If you choose to enable SSH and do not have an existing SSH key stored on AWS, the EB CLI requires ssh-keygen to be available on the path to generate SSH keys.
- Run
eb create -i c4.large --scale 1 --envvars TARGET_URL=<test URL> --instance_profile aws-elasticbeanstalk-locust-role
to begin the creation of your load generation environment. Replace<test URL>
with the URL of the web app that you want to test. Note: If you don't have a default VPC (most AWS accounts created in 2014 or later should have a default VPC in the account) in your account, please substitue the above instance type with c3.large.- Enter the environment name of your choice.
- Enter the CNAME prefix you want to use for this environment.
- Once the environment creation process completes, run
eb open
to open the Locust dashboard and start your tests. - To make changes to the test definition, edit the locustfile.py, save and commit the changes, and run
eb deploy
. - If you'd like to scale out the environment to more than 1 EC2 instance,
- Run
eb scale <number of instances>
. Replace<number of instances>
with the number of EC2 instances you would like the environment to scale out to. - If you are reducing the number of running instances in the above step, run
eb deploy
to reselect the master instance removal has been completed. - Run
eb open
to open the Locust dashboard and start your tests.
- Run
- When you are done with your tests, run
eb terminate --all
to clean up.
Note: Running Locust in distributed mode requires a master/slave architecture. This sample requires that the auto scaling minimum and maximum be set to the same value to ensure that the master isn't terminated by auto scaling. If for some reason the master instance is replaced, an eb deploy
should be all it takes to fix it.