This project provides an AWS-based solution for load testing using ECS and Grafana K6. It leverages a Makefile
for automation, making deployment, testing, and container management straightforward.
Load test scripts are stored into an S3 bucket (ARTIFACTS_BUCKET). When the user runs a load test (1), the container that runs on an ECS task, download the script (2) from the bucket and runs the against the URL (3), passeed through environment variable at execution time.
Upon completition, load testing results are uploaded to an s3 bucket (4) (REPORTS_BUCKET) behind a Cloudfront distribution to serve reports via a public URL (6) protected by basic auth provided by Lambda@edge (7).
An SNS notification (5) will inform the user the end of the test with the URL where is it possible to review the results.
- AWS Account: Set up and configure the AWS CLI.
- Docker: To build and push containers.
- Hadolint: A Docker file linter (https://github.com/hadolint/hadolint)
- Terraform: For deploying infrastructure.
- ECS Cluster: Where the load testing will be deployed to.
git clone https://github.com/yredeployAB/aws-solution-load-testing.git
cd aws-solution-load-testing
python -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
Ensure your AWS CLI is configured with appropriate access:
aws configure
Configure AWS environment variables:
export AWS_REGION=<region>
export AWS_PROFILE=<profile>
In configs/
copy or rename app/environment
to your application and environment prefernces (see README.md).
You can have as many application and environment you want. You will refer to these with TARGET_APP
and TARGET_ENV
when running load testing from the Makefile.
Deploy the required AWS infrastructure using Terraform:
make tf.plan
make tf.apply
Once the infrastructure is created create core/docker/.env
with the values from the terrafoorm output (see core/docker/env.example
for reference).
You also need to update SSM parameters (/load-testing/basic-auth-user
and /load-testing/basic-auth-password
) with your user and password. These are used by the Lambda@Edge to provide basic-auth to your reports.
Build and push the Docker container:
make docker.build
make docker.login
make docker.push
Copy k6 scripts from configs/<application>/<environment>
to the artifact bucket.
ARTIFACTS_BUCKET="<artifacts_bucket>" make artifacts.copy
Copy assets to the assets bucket. Assets are just static html pages that will serve you reports.
index.html
is generated automatically when you upload to the bucket using Jinjia template.
It shows the list of reports generated in a tree folder structure.
REPORTS_BUCCKET="<artifacts_bucket>" REPORTS_URL="<url>" make assets.copy
Execute the K6 scripts for different test types:
TARGET_APP=app1 TARGET_ENV=dev make load.run
Once the load test is completed, it will send a notification through SNS to your email.
Destroy the deployed AWS infrastructure:
make destroy
Here’s an overview of the Makefile
commands for reference:
pre-commit
: Run pre-commit hooks manuallytf.lint.fmt
: Validate terraform and running terraform fmtlint.tf
: Run tflintlint
: Run lint terraform codetf.init
: Initialize terraform state backend and providerstf.plan
: Runs a terraform plantf.apply
: Applies a planned state.tf.destroy
: Destroy resources created by terraform.tf.doc
: Generate terraform documentationdocker.build
: Build the docker image in servicedocker.login
: Login to ECRdocker.push
: Push an image to ECRartifacts.copy
: Copy K6 scripts to the Artifact bucketassets.copy
: Copy assets to the k6 reports web bucketload.run
: Run the load testinghelp
: Prints this help message
- Automated Testing: Run tests using
Makefile
commands for convenience. - Load Testing: Simulate steady traffic to evaluate system performance.
- Spike Testing: Assess system behavior under sudden traffic spikes.
- Stress Testing: Push the system to its limits to find bottlenecks.
- Soak Testing: Sustain traffic for long durations to ensure stability.
- Terraform Errors: Run
terraform validate
manually to debug configuration issues. - K6 Script Errors: Verify the
URL
environment variable is set correctly. - Docker Issues: Ensure the Docker daemon is running and check the
Dockerfile
.
This project is licensed under the MIT License. See the LICENSE file for details.