package software.amazon.rds.eventsubscription; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.SubscriptionNotFoundException; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.Logger; import software.amazon.cloudformation.proxy.ProgressEvent; import software.amazon.cloudformation.proxy.ProxyClient; import software.amazon.cloudformation.proxy.ResourceHandlerRequest; import software.amazon.rds.common.handler.Commons; public class DeleteHandler extends BaseHandlerStd { protected ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest request, final CallbackContext callbackContext, final ProxyClient proxyClient, final Logger logger) { return proxy.initiate("rds::delete-event-subscription", proxyClient, request.getDesiredResourceState(), callbackContext) .translateToServiceRequest(Translator::deleteEventSubscriptionRequest) .makeServiceCall((deleteEventSubscriptionRequest, proxyInvocation) -> proxyInvocation.injectCredentialsAndInvokeV2(deleteEventSubscriptionRequest, proxyInvocation.client()::deleteEventSubscription)) .stabilize((deleteEventSubscriptionRequest, deleteEventSubscriptionResponse, proxyInvocation, model, context) -> isDeleted(model, proxyInvocation)) .handleError((deleteRequest, exception, client, resourceModel, ctx) -> Commons.handleException( ProgressEvent.progress(resourceModel, ctx), exception, DEFAULT_EVENT_SUBSCRIPTION_ERROR_RULE_SET)) .done((deleteRequest, deleteResponse, proxyInvocation, model, context) -> ProgressEvent.defaultSuccessHandler(null)); } protected boolean isDeleted(final ResourceModel model, final ProxyClient proxyClient) { try { proxyClient.injectCredentialsAndInvokeV2(Translator.describeEventSubscriptionsRequest(model), proxyClient.client()::describeEventSubscriptions); return false; } catch (SubscriptionNotFoundException e) { return true; } } }