2
votes

I am trying to use OS Process Sampler to run the aws cli commands in JMeter. I will be running this on docker where JMeter and aws cli both will be installed. But before I can do that, I tried to run this locally on my mac but so far unable to get the aws command to run.

On my local terminal for eg I can run: a. aws --version b. bash j.sh (aws --version) Both returns aws-cli/2.0.8 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev12

This confirms aws cli is available in path to be accessible globally.

However when I run the same command from OS Process sampler, I have tried following: a.

Working Directory: /Users/tester/Downloads/apache-jmeter-5.1.1/bin
Environment: {}
Executing: bash aws --version

enter image description here

RESPONSE: bash: aws --version: No such file or directory

b.

Working Directory: /Users/tester
Environment: {}
Executing: bash j.sh
where j.sh just contains the aws --version command

enter image description here

RESPONSE: j.sh: line 1: aws: command not found

What am I missing?

4
Thanks Vadim for your help with editing my question. - Vikas

4 Answers

1
votes

To run aws cli command in JMeter:

  1. Add OS Process Sampler to your test plan.
  2. In the Command field enter your command: aws.
  3. In the Command Parameters add any parameters you need, for example this one: --version.

enter image description here

  1. Add a View Results Tree to your Thread Group, run the test and see response body:

    aws-cli/2.0.0 Python/3.7.5 Windows/10 botocore/2.0.0dev4

1
votes

For those who need to run AWS CLI v2 commands from JMeter on Windows (I use 10). Below is my setup.

enter image description here

the original command is:

$ aws dynamodb list-tables

Result:

enter image description here

0
votes

I believe you need to configure your OS Process Sampler as follows:

  • Command: /bin/bash
  • Parameter 1: -c
  • Parameter 2: aws --version

    enter image description here

Demo:

enter image description here

From bash manual page:

-c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.

More information: How to Run External Commands and Programs Locally and Remotely from JMeter

0
votes

Thanks Dmitri and Vadim for your response on my question. Unfortunately both examples are for Windows where OS Process sampler will work differently compared to Mac. I got it to work with few more tweaks using OS Process Sampler on Mac as well:

enter image description here

The key difference for Mac is that jmeter needs the location aws cli is installed

/usr/local/bin/aws

I was able to find this via which command

which aws

I also decided to use Beanshell sampler along with logging to do this which will allow me to script and control better my other needs. Here is my reference code that works:

try {

    Process p = Runtime.getRuntime().exec("/usr/local/bin/aws --version");
    p.waitFor();


    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    StringBuilder logCommandOutput = new StringBuilder();
    String line;
    while ((line = in.readLine()) != null) {
        logCommandOutput.append(line);
    } in .close();
    log.info("Output: " + logCommandOutput.toString());
} catch (Exception e) {
    log.error("exception" + e);

}

Hope this helps someone who is trying to do the same.