Create an AWS Summary Through Rust Cli

Hi,
I am trying to convert this command line command "aws ec2 describe-reserved-instances --region us-west-2 --filters Name=state,Values=active,retired > aws_reserved", which essentially creates a file called aws_reserved holding all the specified information. I tried using "use std::process::Command;" followed by
"let awscmd = Command::new("aws")
.arg("ec2 describe-reserved-instances --region us-west-2 --filters
Name=state,Values=active,retired > aws_reserved")
.output()
.expect("failed to execute process");"
However, when I do this, I don't see the aws_reserved file being created. I would really appreciate some help.

It doesn't look like you are passing the arguments right there. Each argument should be passed with a separate arg() call (or as separate entries in a list passed to args()).

Additionally, using > to pipe stdout to a file won't work as that is handled by the shell, and Rust is executing the program directly. You should either use the output you get from the output() method (and write it to a file yourself if you want that), or make the command call an actual shell command (like sh -c), with the entire command (aws ec2 describe-reserved-instances --region us-west-2 --filters Name=state,Values=active,retired > aws_reserved) as a single argument. Which approach may be better depends on what you want to do with the contents of the aws_reserved file.

2 Likes

Thanks, that worked for me.