Container for the parameters to the StopInstances operation.

Stops an Amazon EBS-backed instance. 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.

You can't start or stop Spot Instances.

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.

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.

Performing this operation on an instance that uses an instance store as its root device returns an error.

You can stop, start, and terminate EBS-backed instances. You can only terminate instance store-backed instances. What happens to an instance differs if you stop it or terminate it. For example, when you stop an instance, the root device and any other devices attached to the instance persist. When you terminate an instance, the root device and any other devices attached during the instance launch are automatically deleted. For more information about the differences between stopping and terminating instances, see Instance Lifecycle in the Amazon Elastic Compute Cloud User Guide .

상속: AmazonEC2Request
예제 #1
0
        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();
        }
예제 #2
0
        public static void StopInstance(List<string> instancesId)
        {
            var ec2 = Ec2ConnectionProvider.GetEc2Connection();

            StopInstancesRequest stopInstanceRequest = new StopInstancesRequest()
            {
                InstanceIds = instancesId
            };

            StopInstancesResponse stopResult = ec2.StopInstances(stopInstanceRequest);
        }
 protected override void ProcessRecord()
 {
     AmazonEC2 client = base.GetClient();
     Amazon.EC2.Model.StopInstancesRequest request = new Amazon.EC2.Model.StopInstancesRequest();
     if (string.IsNullOrEmpty(this._InstanceId))
     {
         request.InstanceId.Add(this._InstanceId);
     }
     request.Force = this._Force;
     Amazon.EC2.Model.StopInstancesResponse response = client.StopInstances(request);
     base.WriteObject(response.StopInstancesResult.StoppingInstances, true);
 }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.EC2.Model.StopInstancesRequest();

            if (cmdletContext.Enforce != null)
            {
                request.Force = cmdletContext.Enforce.Value;
            }
            if (cmdletContext.Hibernate != null)
            {
                request.Hibernate = cmdletContext.Hibernate.Value;
            }
            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);
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        /// <summary>
        /// Initiates the asynchronous execution of the StopInstances operation.
        /// <seealso cref="Amazon.EC2.IAmazonEC2.StopInstances"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the StopInstances 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<StopInstancesResponse> StopInstancesAsync(StopInstancesRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new StopInstancesRequestMarshaller();
            var unmarshaller = StopInstancesResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, StopInstancesRequest, StopInstancesResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
        /// <summary>
        /// Stops an Amazon EBS-backed instance. 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>
        /// You can't start or stop Spot Instances.
        /// </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.
        /// </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>
        /// You can stop, start, and terminate EBS-backed instances. You can only terminate instance
        /// store-backed instances. What happens to an instance differs if you stop it or terminate
        /// it. For example, when you stop an instance, the root device and any other devices
        /// attached to the instance persist. When you terminate an instance, the root device
        /// and any other devices attached during the instance launch are automatically deleted.
        /// For more information about the differences between stopping and terminating instances,
        /// see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html">Instance
        /// Lifecycle</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        ///  
        /// <para>
        /// For more information about troubleshooting, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesStopping.html">Troubleshooting
        /// Stopping Your Instance</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the StopInstances service method.</param>
        /// 
        /// <returns>The response from the StopInstances service method, as returned by EC2.</returns>
        public StopInstancesResponse StopInstances(StopInstancesRequest request)
        {
            var marshaller = new StopInstancesRequestMarshaller();
            var unmarshaller = StopInstancesResponseUnmarshaller.Instance;

            return Invoke<StopInstancesRequest,StopInstancesResponse>(request, marshaller, unmarshaller);
        }
예제 #8
0
 private void StopServers(Ec2BootstrapConfig config)
 {
     Logger.WithLogSection("Stopping servers", () =>
     {
         var instanceIds = config.Instances.Select(x => x.InstanceId).ToList();
         var request = new StopInstancesRequest
         {
             InstanceIds = instanceIds
         };
         _client.StopInstances(request);
         _instanceHandler.WaitForInstancesStatus(instanceIds, Ec2InstanceState.Stopped);
     });
 }
예제 #9
0
 IAsyncResult invokeStopInstances(StopInstancesRequest stopInstancesRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new StopInstancesRequestMarshaller().Marshall(stopInstancesRequest);
     var unmarshaller = StopInstancesResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
예제 #10
0
 /// <summary>
 /// <para>Stops an Amazon EBS-backed instance. 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>You can't start or stop Spot Instances.</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.</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>You can stop, start, and terminate EBS-backed instances. You can only terminate instance store-backed instances. What happens to an
 /// instance differs if you stop it or terminate it. For example, when you stop an instance, the root device and any other devices attached to
 /// the instance persist. When you terminate an instance, the root device and any other devices attached during the instance launch are
 /// automatically deleted. For more information about the differences between stopping and terminating instances, see <a
 /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html" >Instance Lifecycle</a> in the <i>Amazon Elastic
 /// Compute Cloud User Guide</i> .</para>
 /// </summary>
 /// 
 /// <param name="stopInstancesRequest">Container for the necessary parameters to execute the StopInstances service method on AmazonEC2.</param>
 /// 
 /// <returns>The response from the StopInstances service method, as returned by AmazonEC2.</returns>
 /// 
 public StopInstancesResponse StopInstances(StopInstancesRequest stopInstancesRequest)
 {
     IAsyncResult asyncResult = invokeStopInstances(stopInstancesRequest, null, null, true);
     return EndStopInstances(asyncResult);
 }
예제 #11
0
 InstanceState Stop(RunningInstance instance)
 {
     using (var client = CreateClient())
     {
         var request = new StopInstancesRequest();
         request.InstanceId.Add(instance.InstanceId);
         var response = client.StopInstances(request);
         return response.StopInstancesResult.StoppingInstances[0].CurrentState;
     }
 }
예제 #12
0
            /// <summary>
            /// Stops an Amazon EBS-backed instance. 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. You can't start or stop Spot Instances.
            /// 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. 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. Performing this operation on an instance that uses an instance store as its root device returns an error.
            /// </summary>
            /// <param name="instances">A list of instance IDs to be stopped.</param>
            /// <param name="settings">The <see cref="EC2Settings"/> used during the request to AWS.</param>
            public bool StopInstances(IList<string> instances, EC2Settings settings)
            {
                if ((instances == null) || (instances.Count == 0))
                {
                    throw new ArgumentNullException("instances");
                }

                

                //Create Request
                AmazonEC2Client client = this.CreateClient(settings);
                StopInstancesRequest request = new StopInstancesRequest();

                foreach (string instance in instances)
                {
                    request.InstanceIds.Add(instance);
                }



                //Check Response
                StopInstancesResponse response = client.StopInstances(request);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    _Log.Verbose("Successfully stopped instances '{0}'", string.Join(",", instances));
                    return true;
                }
                else
                {
                    _Log.Error("Failed to stop instances '{0}'", string.Join(",", instances));
                    return false;
                }
            }
예제 #13
0
        private static void StopInstance()
        {
            try
            {
                AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(_awsKey, _awsSecretKey);

                StopInstancesRequest request = new StopInstancesRequest();
                request.WithInstanceId(new string[] { _instanceId });

                ec2.StopInstances(request);
                Mail(string.Format("Successfully stopped EC2 instance {0}", _instanceId));
            }
            catch (Exception e)
            {
                MailError("Error stopping instance", e);
            }
        }
예제 #14
0
 public void StopInstances(List<string> instanceIds)
 {
     var request = new StopInstancesRequest {InstanceIds = instanceIds};
     _ec2Client.StopInstances(request);
 }
예제 #15
0
        /// <summary>
        /// Stop Amazon EC2 instances.
        /// </summary>
        /// <param name="instances"></param>
        public void StopInstances(string[] instances)
        {
            var request = new StopInstancesRequest { InstanceId = new List<string>(instances) };
            StopInstancesResponse response = Client.StopInstances(request);

            if (response.IsSetStopInstancesResult())
            {
                foreach (InstanceStateChange instanceStateChange in response.StopInstancesResult.StoppingInstances)
                {
                    Trace.WriteLine(string.Format("Stopping instance {0}", instanceStateChange.InstanceId));
                }
            }
        }
예제 #16
0
		internal StopInstancesResponse StopInstances(StopInstancesRequest request)
        {
            var task = StopInstancesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
예제 #17
0
        /// <summary>
        /// <para>Stops an Amazon EBS-backed instance. 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>You can't start or stop Spot Instances.</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.</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>You can stop, start, and terminate EBS-backed instances. You can only terminate instance store-backed instances. What happens to an
        /// instance differs if you stop it or terminate it. For example, when you stop an instance, the root device and any other devices attached to
        /// the instance persist. When you terminate an instance, the root device and any other devices attached during the instance launch are
        /// automatically deleted. For more information about the differences between stopping and terminating instances, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html">Instance Lifecycle</a> in the <i>Amazon Elastic
        /// Compute Cloud User Guide</i> .</para>
        /// </summary>
        /// 
        /// <param name="stopInstancesRequest">Container for the necessary parameters to execute the StopInstances service method on AmazonEC2.</param>
        /// 
        /// <returns>The response from the StopInstances 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<StopInstancesResponse> StopInstancesAsync(StopInstancesRequest stopInstancesRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new StopInstancesRequestMarshaller();
            var unmarshaller = StopInstancesResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, StopInstancesRequest, StopInstancesResponse>(stopInstancesRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
예제 #18
0
 /// <summary>
 /// Stops an EC2 instance
 /// </summary>
 /// <param name="instanceId"></param>
 /// <returns></returns>
 public static EC2Instance StopInstance(string instanceId)
 {
     var instance = new EC2Instance() { InstanceId = instanceId };
     var request = new StopInstancesRequest();
     request.InstanceId = new List<string>();
     request.InstanceId.Add(instanceId);
     try
     {
         var response = EC2.Provider.StopInstances(request);
         var stateChanges = response.StopInstancesResult.StoppingInstances;
         var runningInstance = (from i in stateChanges
                                where i.InstanceId == instanceId
                                select i).FirstOrDefault();
         instance.CurrentStateName = runningInstance.CurrentState.Name;
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Error calling AWS.StopInstances: {0}", ex.Message));
     }
     return instance;
 }
예제 #19
0
 /// <summary>
 /// Initiates the asynchronous execution of the StopInstances operation.
 /// <seealso cref="Amazon.EC2.IAmazonEC2.StopInstances"/>
 /// </summary>
 /// 
 /// <param name="stopInstancesRequest">Container for the necessary parameters to execute the StopInstances 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 EndStopInstances
 ///         operation.</returns>
 public IAsyncResult BeginStopInstances(StopInstancesRequest stopInstancesRequest, AsyncCallback callback, object state)
 {
     return invokeStopInstances(stopInstancesRequest, callback, state, false);
 }
예제 #20
0
 /// <summary>
 /// Stops instances
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public StopInstancesResponse StopInstances(StopInstancesRequest request)
 {
     return EC2.StopInstances(request);
 }
예제 #21
0
        /// <summary>
        /// Stops the instance.
        /// </summary>
        /// <param name="instanceId">The instance id.</param>
        private static void StopInstance(string instanceId)
        {
            var logger = LogManager.GetLogger(typeof(Program));
              logger.Info("Stopping instance");

              var client = AWSClientFactory.CreateAmazonEC2Client(
            Settings.Default.AwsAccessKey, Settings.Default.AwsSecretAccessKey);
              var request = new StopInstancesRequest { InstanceId = { instanceId } };
              client.StopInstances(request);
        }
예제 #22
0
 public StopInstancesResponse StopInstances(StopInstancesRequest request)
 {
     throw new NotImplementedException();
 }
 private Amazon.EC2.Model.StopInstancesResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.StopInstancesRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "StopInstances");
     try
     {
         #if DESKTOP
         return(client.StopInstances(request));
         #elif CORECLR
         return(client.StopInstancesAsync(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;
     }
 }
예제 #24
0
 public void StopInstance(Instance instance)
 {
     var stopRequest = new StopInstancesRequest(new List<string> { instance.InstanceId });
     var stopResult = _client.StopInstances(stopRequest);
     //var stateChangeList = stopResult.StoppingInstances;
 }
예제 #25
0
        /// <summary>
        /// Initiates the asynchronous execution of the StopInstances operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the StopInstances 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 EndStopInstances
        ///         operation.</returns>
        public IAsyncResult BeginStopInstances(StopInstancesRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new StopInstancesRequestMarshaller();
            var unmarshaller = StopInstancesResponseUnmarshaller.Instance;

            return BeginInvoke<StopInstancesRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
예제 #26
0
        /// <summary>
        /// <para> Stops 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> 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. 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 StopInstances service method on AmazonEC2.</param>
        /// 
        /// <returns>The response from the StopInstances service method, as returned by AmazonEC2.</returns>
		public StopInstancesResponse StopInstances(StopInstancesRequest request)
        {
            var task = StopInstancesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the StopInstances operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the StopInstances 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<StopInstancesResponse> StopInstancesAsync(StopInstancesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new StopInstancesRequestMarshaller();
            var unmarshaller = StopInstancesResponseUnmarshaller.Instance;

            return InvokeAsync<StopInstancesRequest,StopInstancesResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
예제 #28
0
 public void StopInstance(string instanceId)
 {
     var ec2 = GetEC2Client();
     var req = new StopInstancesRequest() { Force = true, InstanceIds = new List<string>(new[] { instanceId }) };
     ec2.StopInstances(req);
 }