in aws-iotfleethub-application/src/main/java/software/amazon/iotfleethub/application/DeleteHandler.java [30:72]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final Logger logger) {
ResourceModel model = request.getDesiredResourceState();
if (StringUtils.isEmpty(request.getClientRequestToken())) {
logger.log(String.format("ClientToken is Required, but a client request token was not provided."));
return ProgressEvent.failed(model, callbackContext, HandlerErrorCode.InvalidRequest, "ClientToken was not provided.");
}
// If application id regex is null or invalid, return NotFound to avoid stuck Delete-Failed state in CFN after invalid request
String applicationId = model.getApplicationId();
if (applicationId == null) {
logger.log("Returning NotFound from DeleteHandler due to no Id provided in the model.");
return ProgressEvent.failed(model, callbackContext, HandlerErrorCode.NotFound, "Application Id was not provided.");
} else {
boolean matches = APP_ID_PATTERN.matcher(applicationId).matches();
if (!matches) {
logger.log("Returning NotFound from DeleteHandler due to invalid Id " + applicationId);
return ProgressEvent.failed(model, callbackContext, HandlerErrorCode.NotFound, "Invalid Application Id");
}
}
DeleteApplicationRequest deleteRequest = Translator.translateToDeleteRequest(request, model);
try {
proxy.injectCredentialsAndInvokeV2(deleteRequest, iotFleetHubClient::deleteApplication);
} catch (ResourceNotFoundException e) {
logger.log(String.format("Application with Id %s was not found", model.getApplicationId()));
return ProgressEvent.failed(model, callbackContext, HandlerErrorCode.NotFound, e.getMessage());
} catch (RuntimeException e) {
HandlerErrorCode err = Translator.translateExceptionToErrorCode(e, logger);
return ProgressEvent.failed(model, callbackContext, err, e.getMessage());
}
logger.log(String.format("Deleted Application with Id %s from account %s ",
model.getApplicationId(), request.getAwsAccountId()));
return ProgressEvent.defaultSuccessHandler(null);
}