Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active September 28, 2016 02:13
Show Gist options
  • Select an option

  • Save pcn/6c2b7aa1e7e37cf05730533006e39954 to your computer and use it in GitHub Desktop.

Select an option

Save pcn/6c2b7aa1e7e37cf05730533006e39954 to your computer and use it in GitHub Desktop.
OK ec2 api, what are the expected characters?
```
extern crate docopt;
extern crate rusoto;
extern crate awsshuf;
extern crate serde;
extern crate serde_json;
use rusoto::Region;
use rusoto::ec2::{Ec2Client, DescribeInstancesRequest};
use std::str::FromStr;
use docopt::Docopt;
const USAGE: &'static str = "
Query amazon for a random choice among some set of resources
Display matching resources as a json document.
Usage:
aal [-c | --no-cache] [-a <api>...] [-r <region>...] <pattern>
aal (-h | --help)
Options:
-h --help Show this screen
-c --no-cache Bypass the cached resources info
-r --region=<region> Region (can be specified more than once) [default: us-east-1 us-west-2]
-a --api=<api> Which AWS API, defaults to EC2
";
fn main() {
let version = "0.1.0".to_owned();
let parsed_cmdline = Docopt::new(USAGE)
.and_then(|d| d.version(Some(version)).parse())
.unwrap_or_else(|e| e.exit());
println!("{:?}", parsed_cmdline);
let creds = awsshuf::auth::credentials_provider(None, None);
let r = parsed_cmdline.get_vec("-r");
let reg = Region::from_str(r[0]).unwrap();
let client = Ec2Client::new(creds, reg);
let req = DescribeInstancesRequest::default();
println!("{:?}", req);
match client.describe_instances(&req) {
Ok(response) => {
println!("Got a response");
println!("{:?}", response.reservations.unwrap()[0].instances);
},
Err(error) => {
println!("Error: {:?}", error);
}
}
}
```
$ target/debug/aal .
-a, --api => List([])
-h, --help => Switch(false)
-c, --no-cache => Switch(false)
-r, --region => List(["us-east-1", "us-west-2"])
<pattern> => Plain(Some("."))
DescribeInstancesRequest { dry_run: None, filters: None, instance_ids: None, max_results: None, next_token: None }
Error: Unknown("Expected characters")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment