Super easy load testing for your Serverless APIs and Functions

George Mao
Feb 18 · 3 min read

Serverless moves your unit of scale from servers to number of requests you’re serving concurrently. This means that testing your APIs and functions must be handled differently — you need to test your request or “TPS” concurrency at peak rather than worry about total volume.

One of the most common things you need to do when working with Amazon API Gateway or AWS Lambda functions is to drive load at your serverless resources. One of the best and easiest ways to accomplish this is to use a free Node program called Artillery.


Simply start by installing Artillery via npm:

npm install -g artillery

Then you can use the following command to execute a load test:

artillery run [config file here.yaml]

Testing Lambda

In order to invoke a Lambda function, you’ll need to submit an HTTP POST to the Lambda service endpoint. The endpoint looks like this:

https://lambda.us-east-2.amazonaws.com

(this is region specific, so replace with your region)

You’ll need to provide a valid AWS v4 signature as the Authorization header. Its possible to generate that manually, but we’re going to use an Artillery plugin called artillery-plugin-aws-sigv4. Just npm install it like this:

npm install artillery-plugin-aws-sigv4

Now, you can use Artillery to generate load according to a pattern you specify in the config file. The plugin will perform AWS signature v4 signing for you.

Read here on how to write a config file for Artillery.

This creates phases of load that simulate the traffic you want to test against your Lambda function. In this example, we’re creating 1 load phase that lasts 60 seconds. We start with 10 new users and ramp that up to 50 new users over the 60 seconds. You can add as many load phases as you want.

Once you run this test, it will start providing statistics on the results as the load phase ramps up. You can observe the RPS or Requests Per Second and the details on the response latency. As you can see below, we’re seeing median latency around 120–130ms.

Beginning of the load test. 200 OK success responses for all tests.

Artillery will continue to display test results throughout the test and finally provide you a summary report of all launched tests and the overall response codes:

1862 total invokes to Lambda with 100% success rate

As you can see, this test resulted in a 100% success rate with median response times at 127ms.

If I compare to the metrics recorded in CloudWatch I see that everything matches. Note, I have this function enabled for Provisioned Concurrency to enable the best performance.

1.8k invokes with 100% success rate (200 OK response)

These two metrics are useful in telling me how much of my Provisioned Concurrency allocation my test is using:

100% utilization of my Provisioned Concurrency allocation

You can use this same approach to test HTTP APIs. Just modify your confg file with the correct endpoint and make sure you have a machine that is powerful enough … or use a few EC2 instances :)

George Mao

Written by

AWS Serverless Specialist. I’ll post short, high value tips & tricks for all things Serverless. Ping me if you want to talk about anything :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade