private ProgressEvent checkForPreCreateResourceExistence()

in aws-sns-topic/src/main/java/software/amazon/sns/topic/CreateHandler.java [84:118]


    private ProgressEvent<ResourceModel, CallbackContext> checkForPreCreateResourceExistence(
            final ResourceHandlerRequest<ResourceModel> request,
            final ProxyClient<SnsClient> proxyClient,
            final ProgressEvent<ResourceModel, CallbackContext> progressEvent) {
        final ResourceModel model = progressEvent.getResourceModel();
        final CallbackContext callbackContext = progressEvent.getCallbackContext();

        String awsPartition = request.getAwsPartition();
        String region = request.getRegion();
        String accountId = request.getAwsAccountId();

        logger.log("Parsing Request INFO - Aws Paritiion: " + awsPartition + " - Region: " + region + " - Valid Account Id: " + !StringUtils.isEmpty(accountId));

        try {
            proxyClient.injectCredentialsAndInvokeV2(Translator.translateToGetTopicAttributes(awsPartition, region, accountId, model.getTopicName()), proxyClient.client()::getTopicAttributes);
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .status(OperationStatus.FAILED)
                    .errorCode(HandlerErrorCode.AlreadyExists)
                    .message(model.getTopicName() + " already exists")
                    .build();
        } catch (NotFoundException e) {
            logger.log(model.getTopicName() + " does not exist; creating the resource.");
            return ProgressEvent.progress(model, callbackContext);
        } catch (AuthorizationErrorException e) {
            throw new CfnAccessDeniedException(e);
        } catch (InternalError e) {
            throw new CfnInternalFailureException(e);
        } catch (InvalidParameterException e) {
            throw new CfnInvalidRequestException(e);
        } catch (InvalidSecurityException e) {
            throw new CfnInvalidCredentialsException(e);
        } catch (Exception e) {
            throw new CfnInternalFailureException(e);
        }
    }