Last updated September 18, 2020

Introduction

In Part 1 , we’ve deployed a simple RESTful API to AWS Elastic Beanstalk and set up CI/CD pipelines.

In this part, we’ll integrate BlazeMeter’s automated performance test to our CD pipeline.

BlazeMeter is an open-source-based, enterprise-ready platform that unifies all the functionality you need to shift testing left - and right. We’ll use free

Although you can integrate BlazeMeter into any CodePipeline project, I recommend you to finish Part 1 before you begin.

We’ll use the free tier of BlazeMeter with 50 users. AWS CodePipeline will first deploy our app to Elastic Beanstalk TestEnv environment then will trigger BlazeMeter. BlazeMeter will perform load tests on TestEnv’s ELB endpoints.

Create and integrate BlazeMeter performance test

Get TestEnv DNS address

Navigate to Elastic Load Balancer console and copy DNS address of your TestEnv ELB.

ELB-TestEnv

Create performance test

  • Register to BlazeMeter and navigate to the console.
  • Click Create Test button on the top of the page then click Performance Test.
  1. Give your test a name.
  2. Set Total Users to 50 and Duration to 15 minutes minimum. You can set shorter than 15 minutes. But we want to give enough time to see autoscaling in action.
  3. It’s time to add our API endpoints. Click Enter URL/API Calls.

BlazeMeter

Define scenario

It’s time to add our API endpoints. The API is read-only exposes only the GET method.

Here is a list of all endpoints/methods of out simple API:

# API health check
http://YOUR_TESTENV_ELB_ADDRESS/

# Get all pets
http://YOUR_TESTENV_ELB_ADDRESS/pets

# Get dog
http://YOUR_TESTENV_ELB_ADDRESS/pets/1

# Get cat
http://YOUR_TESTENV_ELB_ADDRESS/pets/2

# Get fish
http://YOUR_TESTENV_ELB_ADDRESS/pets/3

Click the + button under scenario definition and add all requests.

BlazeMeter Scenario-1

Load Distribution and Failure criteria

Now we’ll define the location of requests and when our performance test will fail. We’ll choose the same region as API. (Frankfurt).

We choose error.rate as our failure criteria. If greater than 2% of requests fail, our performance test will fail. You can define multiple conditions.

BlazeMeter Scenario-2

Edit pipeline

Go to AWS CodePipeline console and open the pipeline you’ve created before (node-petshop-api-pipeline) and click Edit. Edit Pipeline

Add BlazeMeter test stage

Scroll down and click the Add stage button below the DeploytoTest stage. Add Stage 1

Give a name to your stage on the popup menu and click Add stage again. We name it as LoadTest. Add Stage 2

Edit action group

Click the Edit action group button inside your new stage. Edit Action Group

Connect to BlazeMeter

  • Give an action name you want. We name it as BlazeMeterPerformanceTest.
  • Select BlazeMeter as action provider.
  • Select SourceArtifact as Input artifacts.
  • Click Connect to BlazeMeter. It will open up blazemeter.com on a popup window.
  • Click Connect on the test you’ve created before. (node-petshop-api-load-test)
  • It’ll integrate BlazeMeter to AWS CodePileline and close the popup window.
  • Click Done. Connect Blazemeter 1

Connect Blazemeter 2

Save pipeline

Click the Save button on the top of the pipeline. Now you’are ready to test! Save Pipeline

Test it out

Now it’s time to trigger our CI/CD pipeline again.

For the sake of simplicity, I won’t follow the Github Flow this time. I’ll make a change to the master branch and push it directly.

Of course, you are free to follow the same test steps we’ve done in Part 1 .

  • Ensure you are on the master branch
git checkout master
  • Open app.js. Make a change or changes in pet prices as you like.
  • Commit and push to the master
git add app.js
git commit -m "Update prices"
git push origin master

Now it’ll trigger our CD pipeline. Go to CodePipeline console and watch it.

When it comes to the LoadTest stage, open the BlazeMeter console, and see how your performance test is running.

While the performance test is running, go to the EC2 console and watch how AWS spins up new instances, how autoscaling works.

BlazeMeter performance test is running

BlazeMeter test running

Autoscaling in action

EC2 Scaling

Clean Up

Don’t forget to destroy AWS resources to avoid unexpected charges.

# Delete pipeline
aws cloudformation delete-stack --stack-name node-petshop-api-cd-pipeline
# Delete Elastic Beanstalk environments
aws cloudformation delete-stack --stack-name node-petshop-api-ebs
# Delete bucket
aws s3 rb s3://${S3_BUCKET_NAME} --force