static void Main(string[] args) { try { var argsDic = GetArgsDic(args); var itemsList = argsDic["--instances"]; if (itemsList.StartsWith("\"") && itemsList.EndsWith("\"")) { itemsList = itemsList.Substring(1, itemsList.Length - 2); } var items = itemsList.Split(','); var action = argsDic["--action"]; using (var client = AwsUtil.CreateClient(AwsUtil.Region)) { if (action == "start") { var request = new StartInstancesRequest(); request.InstanceId.AddRange(items); client.StartInstances(request); } else if (action == "stop") { var request = new StopInstancesRequest(); request.InstanceId.AddRange(items); client.StopInstances(request); } } } catch (ApplicationException exc) { Console.WriteLine(exc.Message); } catch (AmazonEC2Exception exc) { Console.WriteLine(exc.Message); } catch (Exception exc) { Console.WriteLine(exc); } }
AmazonEC2Client CreateClient() { return(AwsUtil.CreateClient(AwsRegion)); }