Ejemplo n.º 1
0
        public async Task DeleteSchedulerRuleAsync(string ruleName)
        {
            // list targets by rule name
            List <string> targetIds = new List <string>();

            try
            {
                var response = await _cloudWatchClient.ListTargetsByRuleAsync(new ListTargetsByRuleRequest()
                {
                    Rule = ruleName
                });

                var foundTargetIds = from target in response.Targets
                                     select target.Id;

                targetIds = foundTargetIds.ToList();
            }
            catch (AmazonCloudWatchEventsException)
            {
                throw;
            }

            // remove targets from rule
            try
            {
                await _cloudWatchClient.RemoveTargetsAsync(new RemoveTargetsRequest()
                {
                    Rule  = ruleName,
                    Ids   = targetIds,
                    Force = true
                });
            }
            catch (AmazonCloudWatchEventsException)
            {
                throw;
            }

            // finally delete rule
            try
            {
                await _cloudWatchClient.DeleteRuleAsync(new DeleteRuleRequest()
                {
                    Name  = ruleName,
                    Force = true
                });
            }
            catch (AmazonCloudWatchEventsException)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
 private Amazon.CloudWatchEvents.Model.DeleteRuleResponse CallAWSServiceOperation(IAmazonCloudWatchEvents client, Amazon.CloudWatchEvents.Model.DeleteRuleRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon CloudWatch Events", "DeleteRule");
     try
     {
         #if DESKTOP
         return(client.DeleteRule(request));
         #elif CORECLR
         return(client.DeleteRuleAsync(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;
     }
 }