Run AWS CLI from java

I'm trying to run AWS CLI commands directly from java code.

The reason for that is because AWS Java SDK does not allow to create redirects and I need to create a redirect somehow from a Java application.

So far my code looks as follows:

private String runAwsCli(String cliCommand) {

ProcessBuilder processBuilder = new ProcessBuilder(cliCommand);

Process process = processBuilder.start();

try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {

return IOUtils.toString(bufferedReader);

}

}

However, when this method is invoked I get:

java.io.IOException: error=2, No such file or directory

at java.lang.UNIXProcess.forkAndExec(Native Method) ~[na:1.8.0_151]

at java.lang.UNIXProcess.(UNIXProcess.java:247) ~[na:1.8.0_151]

at java.lang.ProcessImpl.start(ProcessImpl.java:134) ~[na:1.8.0_151]

I would really appreciate any help,

Thanks!...

Read More »

By: StackOverFlow - 5 days ago

Related Posts