I've been recently given the task of connecting to dynamo DB via SOAP UI in order to assert that my companies APIs are creating the correct content. After hitting a number of brick walls attempting to access Dynamo DB data, we've settled on connecting via a groovy script using windows powershell to utilize AWS CLI and it's authorization provided by Amazon.
I have gone through and configured the AWS CLI, and am able to run commands as expected via power shell, for example:
$ aws dynamodb scan --table-name Accounts
$ aws dynamodb get-item --table-name Accounts --key '{\"id\":{\"S\":\"3b7e2c4a-f672-4a12-b2bc-7313b60b0a9a\"}}'
When switching over to groovy scripts in SOAP UI, the first query works as expected, but the second issue throws the error: "Error parsing parameter '--key': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"
Here is a snippet of the code of cobbled together from various internet sources that I've been using to run the powershell command:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//Get details and Build the command
String powerShellCommand = context.expand( '${#TestCase#PowerShellCommand}' )
String command = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command \"${powerShellCommand}\""
// Executing the command
Process powerShellProcess = Runtime.getRuntime().exec(command);
// Getting the results
powerShellProcess.getOutputStream().close();
String line;
//-----------------------------------------------
//Run query
BufferedReader stdout = new BufferedReader(new InputStreamReader(
powerShellProcess.getInputStream()));
String jsonString = "";
while ((line = stdout.readLine()) != null) {
jsonString = jsonString.concat(line);
}
stdout.close();
//-----------------------------------------------
//Error stuff:
BufferedReader stderr = new BufferedReader(new InputStreamReader(
powerShellProcess.getErrorStream()));
while ((line = stderr.readLine()) != null) {
log.info(line);
}
stderr.close();
//-----------------------------------------------
log.info(jsonString);
I belive it may have somthing to do witht he placment of quotes and exscapes but as yet have not found the corret combination, i belive this to be my current input into powershell:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command "aws dynamodb get-item --table-name Platform.Accounts --key '{\"id\":{\"S\":\"3b7e2c4a-f672-4a12-b2bc-7313b60b0a9a\"}}'"
I have even tried a modified version of the code above where i would post in just the AWS command but this just returns a diffrent error: Error parsing parameter '--key': Expected: '=', received: ''' for input:
The reason this has stumped me is because this command works as expected when going directly to windows powershell.