Logo

dev-resources.site

for different kinds of informations.

Load Testing using K6 in AWS and Terraform

Published at
7/14/2023
Categories
testing
aws
grafana
k6
Author
bensonmichael92
Categories
4 categories in total
testing
open
aws
open
grafana
open
k6
open
Author
15 person written this
bensonmichael92
open
Load Testing using K6 in AWS and Terraform

Summary:

This article talks about how you can deploy your K6 tests in AWS using Terraform and execute them from Gitlab pipeline.

Tools:

  1. K6 load testing framework.
  2. Grafana.
  3. InfluxDB.

Steps:

  1. Build an EC2 instance to run k6 using the following code:
provider "aws" {
  region  = "us-west-2"
  version = "~> 2.8"
}

data "template_file" "user_data" {
  template = file("${path.module}/_templates/k6_data.sh")
}

# The EC2 instance
resource "aws_instance" "k6_instance" {

  ami           = var.ami
  instance_type = var.instance_type
  key_name      = var.key_pair
  user_data     = data.template_file.user_data.rendered
  vpc_security_group_ids = ["${aws_security_group.default.id}"]
  subnet_id = var.key_pair

}
Enter fullscreen mode Exit fullscreen mode

In the parent folder create a file named k6_data.sh under templates folder and add the script to install k6. This will run after the instance is started.

wget https://bintray.com/loadimpact/rpm/rpm -O bintray-loadimpact-rpm.repo
sudo mv bintray-loadimpact-rpm.repo /etc/yum.repos.d/
sudo yum install -y k6
Enter fullscreen mode Exit fullscreen mode

In the similar way we need to create instances for Grafana and influx DB to run and add user data configs which will be initiated once the EC2 instances are up.

For Grafana:

wget https://dl.grafana.com/oss/release/grafana-7.1.0-1.x86_64.rpm
sudo yum install -y grafana-7.1.0-1.x86_64.rpm
sudo service grafana-server start
sudo /sbin/chkconfig --add grafana-server
Enter fullscreen mode Exit fullscreen mode

For Influx DB:

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.6.x86_64.rpm
sudo yum localinstall -y influxdb-1.7.6.x86_64.rpm
sudo systemctl enable influxdb.service
Enter fullscreen mode Exit fullscreen mode

In Influx DB after installing the service we need to create data directories, Users and a database.

This should be done after starting the service using systemctl

influx -execute "create user admin with password 'mongoose123' with all privileges"
influx -execute "create user itguy with password 'itguy123' "
influx -execute "create database k6LoadTestDB"
influx -execute "grant ALL on k6LoadTestDB to grafana"

Enter fullscreen mode Exit fullscreen mode

In order for Grafana to run generate reports from the data in Influx DB during test execution we need to configure Grafana to listen to the port in the Load Balancer.

Hope this article helps !!!!

k6 Article's
30 articles in total
Favicon
Performance testing of OpenAI-compatible APIs (K6+Grafana)
Favicon
A Guide to Scalable and Heavy Load Testing with k6 + Testkube
Favicon
When k6 eats up your RAM: Slashing memory usage in load tests
Favicon
Grafana K6 cheat sheet: everything a performance engineer should know
Favicon
How to send more requests with variable payload size in K6?
Favicon
How to integrate k6 with Xray/Jira
Favicon
Mastering Performance Testing with K6: A Guide for QA Testers
Favicon
Improved k6 Load Test Script with Custom Metrics, Tags, and Labels
Favicon
Como Realizar Testes de Carga com k6
Favicon
Visualização de métricas k6 em tempo real com Prometheus remote write
Favicon
Criando um modulo xk6 para k6
Favicon
Load Testing a Non-API Laravel Web Application with Sanctum Session-Based Authentication Using K6
Favicon
Load and stress testing with k6
Favicon
Enviando notificações com xk6 notification ✉
Favicon
Gerando dados com K6 utilizando xk6-faker
Favicon
Gerando dashboard ao resultado de saida com K6🖼
Favicon
Adicionando percentil ao resultado de saída do K6📊
Favicon
Performance testing Strimzi Kafka in the k8s cluster using xk6-kafka
Favicon
Entendendo as métricas do K6 - Parte 3
Favicon
Node.js Observability Tool: Enhance Visibility Without Performance Impact
Favicon
Optimizing Performance Testing with Docker: K6, InfluxDB, and Grafana Integration
Favicon
Entendendo as métricas do K6 - Parte 2
Favicon
Entendendo as métricas do K6 - Parte 1
Favicon
K6 Development: Beyond The Basic Setup
Favicon
Load Testing Serverless Application using k6
Favicon
Load Testing using K6 in AWS and Terraform
Favicon
Utilizando módulos do xk6 com k6
Favicon
Abortando testes com falhas no K6
Favicon
Utilizando AWS Secret Manager com K6🔐
Favicon
Realizando requisições com query params com K6

Featured ones: