K6 open() not able to find json file

Hi all I am fairly new to k6 and currently having trouble opening a json file. I followed the examples provided here JavaScript API: open and can run this locally. But when trying to run this in aws I keep getting this error :

time="2022-08-08T14:09:52Z" level=error msg="GoError: stat /data.json: no such file or directory\n\tat go.k6.io/k6/js.(*InitContext).Open-fm (native)\n\tat file:///-:11:25(4)\n\tat file:///-:10:13(57)\n\tat native\n" hint="script exception"

My folder structure looks like this currently: Gen/proj/api/test/k6/
In this folder I have script.js and data.json

in script.js I have:

const data = new SharedArray('users', () => {
    const f = JSON.parse(open('./data.json'));
    return f;
});

would anyone be able to help me understand why i get that error ? Ive tried both relative and absolute paths. Ive tried with mounting and without mounting and still results in the same error. is there a specific import for invoking open() ?

Actually ive figured it out. The issue was I mounted incorrectly but was able to sort it out :slight_smile:

1 Like

@nazad23 could you please let me know what is the right way to mount?

Hi @nazad23

I’m not sure how you run this in aws. If it’s with docker, the best way is probably to mount the volume where the script is. You can follow Save json when using docker to run k6 - #2 by imiric

I hope this helps.

Cheers!