void ToggleInstanceState(object sender, RoutedEventArgs e) { if (this.targetInstance == null) { Console.WriteLine("Error: Instance does not exist"); return; } ActionButton.Content = "Please wait..."; using (var awsClient = GetClient()) { if (targetInstance.State.Code > 64) { StartInstancesRequest req = new Amazon.EC2.Model.StartInstancesRequest(); req.InstanceIds.Add(targetInstance.InstanceId); awsClient.StartInstances(req); } else { StopInstancesRequest req = new Amazon.EC2.Model.StopInstancesRequest(); req.InstanceIds.Add(targetInstance.InstanceId); awsClient.StopInstances(req); } } UpdateUI(); }
protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.StartInstancesRequest request = new Amazon.EC2.Model.StartInstancesRequest(); if (string.IsNullOrEmpty(this._InstanceId)) { request.InstanceId.Add(this._InstanceId); } Amazon.EC2.Model.StartInstancesResponse response = client.StartInstances(request); base.WriteObject(response.StartInstancesResult.StartingInstances, true); }
public static void StartInstance(List<string> instancesId) { var ec2 = Ec2ConnectionProvider.GetEc2Connection(); StartInstancesRequest startInstanceRequest = new StartInstancesRequest() { InstanceIds = instancesId }; StartInstancesResponse startResult = ec2.StartInstances(startInstanceRequest); }
private static void LaunchInstance() { try { AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(_awsKey, _awsSecretKey); StartInstancesRequest request = new StartInstancesRequest(); request.WithInstanceId(new string[] { _instanceId }); ec2.StartInstances(request); Mail(string.Format("Successfully started EC2 instance {0}", _instanceId)); } catch (Exception e) { MailError("Error launching instance", e); } }
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); } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.StartInstancesRequest(); if (cmdletContext.AdditionalInfo != null) { request.AdditionalInfo = cmdletContext.AdditionalInfo; } if (cmdletContext.InstanceId != null) { request.InstanceIds = cmdletContext.InstanceId; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
/// <summary> /// Starts an EC2 instance /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public static EC2Instance StartInstance(string instanceId) { var instance = new EC2Instance() { InstanceId = instanceId }; var request = new StartInstancesRequest(); request.InstanceId = new List<string>(); request.InstanceId.Add(instanceId); try { var response = EC2.Provider.StartInstances(request); var stateChanges = response.StartInstancesResult.StartingInstances; var runningInstance = (from i in stateChanges where i.InstanceId == instanceId select i).FirstOrDefault(); if (runningInstance != null) { instance.CurrentStateName = runningInstance.CurrentState.Name; } } catch (Exception ex) { MessageBox.Show(string.Format("Error calling AWS.StartInstances: {0}", ex.Message)); } return instance; }
/// <summary> /// Initiates the asynchronous execution of the StartInstances operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.StartInstances"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the StartInstances operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<StartInstancesResponse> StartInstancesAsync(StartInstancesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new StartInstancesRequestMarshaller(); var unmarshaller = StartInstancesResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, StartInstancesRequest, StartInstancesResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
internal StartInstancesResponse StartInstances(StartInstancesRequest request) { var task = StartInstancesAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Start's instances - these should be EBS block storage instances. /// </summary> /// <param name="instanceIds">The instance Id of an EC2 instance</param> /// <remarks>This uses EBS storage EC2 instances which can be stopped and started. The instance should be stopped.</remarks> public void StartInstances(IEnumerable<string> instanceIds) { var request = new StartInstancesRequest { InstanceId = new List<string>(instanceIds) }; StartInstancesResponse resonse = Client.StartInstances(request); if (resonse.IsSetStartInstancesResult()) { foreach (InstanceStateChange instanceStateChange in resonse.StartInstancesResult.StartingInstances) { Trace.WriteLine(string.Format("Starting instance {0}", instanceStateChange.InstanceId)); } } }
/// <summary> /// <para> Starts an instance that uses an Amazon EBS volume as its root device. Instances that use Amazon EBS volumes as their root devices can /// be quickly stopped and started. When an instance is stopped, the compute resources are released and you are not billed for hourly instance /// usage. However, your root partition Amazon EBS volume remains, continues to persist your data, and you are charged for Amazon EBS volume /// usage. You can restart your instance at any time. </para> <para><b>NOTE:</b> Performing this operation on an instance that uses an instance /// store as its root device returns an error. </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the StartInstances service method on /// AmazonEC2.</param> /// /// <returns>The response from the StartInstances service method, as returned by AmazonEC2.</returns> public StartInstancesResponse StartInstances(StartInstancesRequest request) { var task = StartInstancesAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// Initiates the asynchronous execution of the StartInstances operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the StartInstances operation on AmazonEC2Client.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndStartInstances /// operation.</returns> public IAsyncResult BeginStartInstances(StartInstancesRequest request, AsyncCallback callback, object state) { var marshaller = new StartInstancesRequestMarshaller(); var unmarshaller = StartInstancesResponseUnmarshaller.Instance; return BeginInvoke<StartInstancesRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Starts an Amazon EBS-backed AMI that you've previously stopped. /// /// /// <para> /// Instances that use Amazon EBS volumes as their root devices can be quickly stopped /// and started. When an instance is stopped, the compute resources are released and you /// are not billed for hourly instance usage. However, your root partition Amazon EBS /// volume remains, continues to persist your data, and you are charged for Amazon EBS /// volume usage. You can restart your instance at any time. Each time you transition /// an instance from stopped to started, Amazon EC2 charges a full instance hour, even /// if transitions happen multiple times within a single hour. /// </para> /// /// <para> /// Before stopping an instance, make sure it is in a state from which it can be restarted. /// Stopping an instance does not preserve data stored in RAM. /// </para> /// /// <para> /// Performing this operation on an instance that uses an instance store as its root device /// returns an error. /// </para> /// /// <para> /// For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html">Stopping /// Instances</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the StartInstances service method.</param> /// /// <returns>The response from the StartInstances service method, as returned by EC2.</returns> public StartInstancesResponse StartInstances(StartInstancesRequest request) { var marshaller = new StartInstancesRequestMarshaller(); var unmarshaller = StartInstancesResponseUnmarshaller.Instance; return Invoke<StartInstancesRequest,StartInstancesResponse>(request, marshaller, unmarshaller); }
public void StartInstances(List<string> instanceIds) { var request = new StartInstancesRequest {InstanceIds = instanceIds}; _ec2Client.StartInstances(request); }
/// <summary> /// Initiates the asynchronous execution of the StartInstances operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.StartInstances"/> /// </summary> /// /// <param name="startInstancesRequest">Container for the necessary parameters to execute the StartInstances operation on AmazonEC2.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndStartInstances /// operation.</returns> public IAsyncResult BeginStartInstances(StartInstancesRequest startInstancesRequest, AsyncCallback callback, object state) { return invokeStartInstances(startInstancesRequest, callback, state, false); }
/// <summary> /// <para>Starts an Amazon EBS-backed AMI that you've previously stopped.</para> <para>Instances that use Amazon EBS volumes as their root /// devices can be quickly stopped and started. When an instance is stopped, the compute resources are released and you are not billed for /// hourly instance usage. However, your root partition Amazon EBS volume remains, continues to persist your data, and you are charged for /// Amazon EBS volume usage. You can restart your instance at any time. Each time you transition an instance from stopped to started, Amazon EC2 /// charges a full instance hour, even if transitions happen multiple times within a single hour.</para> <para>Before stopping an instance, make /// sure it is in a state from which it can be restarted. Stopping an instance does not preserve data stored in RAM.</para> <para>Performing /// this operation on an instance that uses an instance store as its root device returns an error.</para> <para>For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html">Stopping Instances</a> in the <i>Amazon Elastic Compute Cloud /// User Guide</i> .</para> /// </summary> /// /// <param name="startInstancesRequest">Container for the necessary parameters to execute the StartInstances service method on /// AmazonEC2.</param> /// /// <returns>The response from the StartInstances service method, as returned by AmazonEC2.</returns> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<StartInstancesResponse> StartInstancesAsync(StartInstancesRequest startInstancesRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new StartInstancesRequestMarshaller(); var unmarshaller = StartInstancesResponseUnmarshaller.GetInstance(); return Invoke<IRequest, StartInstancesRequest, StartInstancesResponse>(startInstancesRequest, marshaller, unmarshaller, signer, cancellationToken); }
InstanceState Start(RunningInstance instance) { using (var client = CreateClient()) { var request = new StartInstancesRequest(); request.InstanceId.Add(instance.InstanceId); var response = client.StartInstances(request); return response.StartInstancesResult.StartingInstances[0].CurrentState; } }
/// <summary> /// Starts an Amazon EBS-backed AMI that you've previously stopped. Instances that use Amazon EBS volumes as their root devices can be quickly stopped /// and started. When an instance is stopped, the compute resources are released and you are not billed for hourly instance usage. However, your root partition /// Amazon EBS volume remains, continues to persist your data, and you are charged for Amazon EBS volume usage. You can restart your instance at any time. Each /// time you transition an instance from stopped to started, Amazon EC2 charges a full instance hour, even if transitions happen multiple times within a single hour. /// </summary> /// <param name="instances">A list of instance IDs to be started.</param> /// <param name="settings">The <see cref="EC2Settings"/> used during the request to AWS.</param> public bool StartInstances(IList<string> instances, EC2Settings settings) { if ((instances == null) || (instances.Count == 0)) { throw new ArgumentNullException("instances"); } //Create Request AmazonEC2Client client = this.CreateClient(settings); StartInstancesRequest request = new StartInstancesRequest(); foreach (string instance in instances) { request.InstanceIds.Add(instance); } //Check Response StartInstancesResponse response = client.StartInstances(request); if (response.HttpStatusCode == HttpStatusCode.OK) { _Log.Verbose("Successfully started instances '{0}'", string.Join(",", instances)); return true; } else { _Log.Error("Failed to start instances '{0}'", string.Join(",", instances)); return false; } }
/// <summary> /// <para>Starts an Amazon EBS-backed AMI that you've previously stopped.</para> <para>Instances that use Amazon EBS volumes as their root /// devices can be quickly stopped and started. When an instance is stopped, the compute resources are released and you are not billed for /// hourly instance usage. However, your root partition Amazon EBS volume remains, continues to persist your data, and you are charged for /// Amazon EBS volume usage. You can restart your instance at any time. Each time you transition an instance from stopped to started, Amazon EC2 /// charges a full instance hour, even if transitions happen multiple times within a single hour.</para> <para>Before stopping an instance, make /// sure it is in a state from which it can be restarted. Stopping an instance does not preserve data stored in RAM.</para> <para>Performing /// this operation on an instance that uses an instance store as its root device returns an error.</para> <para>For more information, see <a /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html" >Stopping Instances</a> in the <i>Amazon Elastic Compute Cloud /// User Guide</i> .</para> /// </summary> /// /// <param name="startInstancesRequest">Container for the necessary parameters to execute the StartInstances service method on /// AmazonEC2.</param> /// /// <returns>The response from the StartInstances service method, as returned by AmazonEC2.</returns> /// public StartInstancesResponse StartInstances(StartInstancesRequest startInstancesRequest) { IAsyncResult asyncResult = invokeStartInstances(startInstancesRequest, null, null, true); return EndStartInstances(asyncResult); }
/// <summary> /// Starts instances /// </summary> /// <param name="request"></param> /// <returns></returns> public StartInstancesResponse StartInstances(StartInstancesRequest request) { return EC2.StartInstances(request); }
IAsyncResult invokeStartInstances(StartInstancesRequest startInstancesRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new StartInstancesRequestMarshaller().Marshall(startInstancesRequest); var unmarshaller = StartInstancesResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
public StartInstancesResponse StartInstances(StartInstancesRequest request) { throw new NotImplementedException(); }
private void StartServers(Ec2BootstrapConfig config) { Logger.WithLogSection("Starting servers", () => { var instanceIds = config.Instances.Select(x => x.InstanceId).ToList(); var request = new StartInstancesRequest { InstanceIds = instanceIds }; _client.StartInstances(request); _instanceHandler.WaitForInstancesStatus(instanceIds, Ec2InstanceState.Running); }); }
public void StartInstance(Instance instance) { var startRequest = new StartInstancesRequest(new List<string> { instance.InstanceId }); var startResult = _client.StartInstances(startRequest); //var stateChangeList = startResult.StartingInstances; }
public void StartUpInstance(Ec2Key ec2Key, string instanceId) { _logger.Debug("DeleteSnapshot Start."); AmazonEC2 ec2 = CreateAmazonEc2Client(ec2Key); var request = new StartInstancesRequest { InstanceId = new List<string> { instanceId } }; ec2.StartInstances(request); _logger.Debug("StartUpInstance End."); }
private Amazon.EC2.Model.StartInstancesResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.StartInstancesRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "StartInstances"); try { #if DESKTOP return(client.StartInstances(request)); #elif CORECLR return(client.StartInstancesAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// Initiates the asynchronous execution of the StartInstances operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the StartInstances operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<StartInstancesResponse> StartInstancesAsync(StartInstancesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new StartInstancesRequestMarshaller(); var unmarshaller = StartInstancesResponseUnmarshaller.Instance; return InvokeAsync<StartInstancesRequest,StartInstancesResponse>(request, marshaller, unmarshaller, cancellationToken); }
public void StartInstance(string instanceId) { var ec2 = GetEC2Client(); var req = new StartInstancesRequest() { InstanceIds = new List<string>(new[] { instanceId }) }; ec2.StartInstances(req); }