Created
May 28, 2018 13:31
-
-
Save eagletmt/c83b4ba29255458af84fdc2a642c8083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate env_logger; | |
extern crate rusoto_ec2; | |
fn main() { | |
use rusoto_ec2::Ec2; | |
env_logger::init(); | |
// my VPC case in ap-northeast-1 region | |
let image_id = "ami-7a1be605"; | |
let subnet_ids = ["subnet-823cd2ea", "subnet-813cd2e9", "subnet-1248393a"]; | |
let instance_types = [ | |
"t2.micro", | |
"t2.small", | |
"t2.medium", | |
"t2.large", | |
"t2.xlarge", | |
"t2.2xlarge", | |
"m4.large", | |
// Adding the line below causes `Err(Unknown(""))` error | |
// "m4.xlarge", | |
]; | |
let launch_specifications = instance_types | |
.iter() | |
.flat_map(|instance_type| { | |
subnet_ids | |
.iter() | |
.map(|subnet_id| rusoto_ec2::SpotFleetLaunchSpecification { | |
image_id: Some(image_id.to_owned()), | |
spot_price: Some("0.001".to_owned()), | |
instance_type: Some(instance_type.to_string()), | |
subnet_id: Some(subnet_id.to_string()), | |
weighted_capacity: Some(1.0), | |
block_device_mappings: Some(vec![ | |
rusoto_ec2::BlockDeviceMapping { | |
device_name: Some("/dev/sda1".to_owned()), | |
ebs: Some(rusoto_ec2::EbsBlockDevice { | |
delete_on_termination: Some(true), | |
volume_size: Some(20), | |
volume_type: Some("gp2".to_owned()), | |
..Default::default() | |
}), | |
..Default::default() | |
}, | |
]), | |
..Default::default() | |
}) | |
.collect::<Vec<rusoto_ec2::SpotFleetLaunchSpecification>>() | |
}) | |
.collect(); | |
let ec2_client = rusoto_ec2::Ec2Client::simple(Default::default()); | |
let resp = ec2_client | |
.request_spot_fleet(&rusoto_ec2::RequestSpotFleetRequest { | |
spot_fleet_request_config: rusoto_ec2::SpotFleetRequestConfigData { | |
iam_fleet_role: "arn:aws:iam::274147449864:role/AmazonEC2SpotFleetTaggingRole" | |
.to_owned(), | |
launch_specifications: Some(launch_specifications), | |
target_capacity: 0, | |
..Default::default() | |
}, | |
..Default::default() | |
}) | |
.sync(); | |
println!("{:?}", resp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment