コード例 #1
0
        /// <summary>
        /// signals AWS to move on from terminate
        /// wait by completing the action
        /// </summary>
        public bool TryCompleteTerminateWait()
        {
            bool returnValue = false;

            //Ok now  its complicated, we need the LifecycleHookName and LifecycleActionToken
            //        to complete the request, there should be a message for us in the queue
            if (!(_TerminatingLifeCycleHookName.IsNullOrWhiteSpace()))
            {
                using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
                {
                    CompleteLifecycleActionRequest completeLifecycleActionRequest = new CompleteLifecycleActionRequest
                    {
                        InstanceId            = _InstanceId,
                        LifecycleActionResult = "CONTINUE",
                        AutoScalingGroupName  = _AutoScalingGroupName,
                        LifecycleHookName     = _TerminatingLifeCycleHookName
                    };
                    try
                    {
                        CompleteLifecycleActionResponse completeLifecycleActionResponse = scalingClient.CompleteLifecycleActionAsync(completeLifecycleActionRequest).Result;
                        if (completeLifecycleActionResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            returnValue = true;
                        }
                    }
                    catch (Exception)
                    {
                        //Yes AWS throws Exceptions and System.AggregrateExceptions
                        //so for now this is the right way to handle it
                        returnValue = false;
                    }
                }
            }
            return(returnValue);
        }