Load JSON document from CSV file
See original GitHub issueMy lambda function which I want to test expects a complex json and as per my understanding it needs to go into the csv file. My problem is I have tried various ways to load the json from csv but keep getting errors. I am not sure if this is even possible. My sample csv document looks like:
column1 { “profile”:{“name”:“irfan”,“email”:“irfan@email.com”},“address”:[“address1”,“address2”]} { “profile”:{“name”:“Tomas”,“email”:“tomas@email.com”},“address”:[“address1”,“address2”]} { “profile”:{“name”:“Joel”,“email”:“joel@email.com”},“address”:[“address1”,“address2”]}
I only have one column because all I want is this json document to get passed as request body to my hello world lambda so I could load test it.
My Artillery script file looks like:
config:
target: "https://api-gateway-load-testing-tst-ap-southeast-2.xxxxxxxxxxx.com"
phases:
-
duration: 5
arrivalRate: 1
defaults:
headers:
x-api-key: "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
Content-Type: "application/json"
payload:
# path is relative to the location of the test script
path: "post-data.csv"
fields:
- "column1"
order: sequence
delimiter: "~"
skipHeader: true
cast: false
plugins:
cloudwatch:
namespace: "serverless-artillery-loadtest"
scenarios:
- flow:
- post:
url: "/v1/hello-world"
json:
data: {{ column1 }}
When I put double quotes around keys and values in the json I get error saying “Error executing task: ERROR exception encountered while executing load from 1579692773908 in 1579692773908: Artillery exited with non-zero code:”
Is there any way to load the json from csv in a way that my hello world lambda function receive request body as json in the following format:
{ “data”: { “profile”:{“name”:“irfan”,“email”:“irfan@email.com”},“address”:[“address1”,“address2”]}}
Any help would be appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
I managed to get around this issue myself by writing custom JavaScript to load json payload instead of from a csv file. I used config.processor along with beforeScenario hook to define the my custom logic.
For anyone who may be facing the similar problem, here is my solution:
script.yml
Following post-body.js contains my custom JS logic. I have introduced a new txt file post-data.txt which essentially replaces csv file which I mentioned in the question to host thousands of rows where each row is a request payload as json. Every time a scenario is executed, a random json payload string is picked up, converted to json object and sent as part of POST request. I am also using CloudWatch and InfluxDB to output the results.
post-body.js
post-data.txt
HTH
hi @ianonymousdev, something like this should work:
I’d suggest running your scripts with
artillery
locally first - that way you will see an actual error message rather than a generic error message from AWS Lambda.