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: error=2, No such file or directory

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

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

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

I would really appreciate any help,


Read More »

By: StackOverFlow - Friday, 9 November

Related Posts