Scripting examples on how to use different authentication or authorization methods in your load test.
AWS Signature v4 authentication
Requests to the AWS APIs requires a special type of auth, called AWS Signature Version 4. k6 does not support this authentication mechanism out of the box, so we'll have to resort to using a Node.js library called awsv4.js and Browserify (to make it work in k6).
For this to work, we first need to do the following:
Make sure you have the necessary prerequisites installed: Node.js and Browserify
Install the awsv4.js library:
Run it through browserify:
Move the aws4.js file to the same folder as your script file. Now you can import it into your test script:
Here's an example script to list all the regions available in EC2. Note that the AWS access key and secret key needs to be provided through environment variables.
⚠️ CPU- and Memory-heavy
As the browserified version of this Node.js library includes several Node.js APIs implemented in pure JS (including crypto APIs) it will be quite heavy on CPU and memory hungry when run with more than just a few VUs.