package software.amazon.ecr.replicationconfiguration; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.services.ecr.EcrClient; import software.amazon.awssdk.services.ecr.model.PutReplicationConfigurationResponse; import software.amazon.cloudformation.exceptions.ResourceNotFoundException; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.HandlerErrorCode; import software.amazon.cloudformation.proxy.Logger; import software.amazon.cloudformation.proxy.OperationStatus; import software.amazon.cloudformation.proxy.ProgressEvent; import software.amazon.cloudformation.proxy.ProxyClient; import software.amazon.cloudformation.proxy.ResourceHandlerRequest; public class UpdateHandler extends BaseHandlerStd { @Override public ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest request, final CallbackContext callbackContext, final ProxyClient proxyClient, final Logger logger) { final ResourceModel model = request.getDesiredResourceState(); final EcrClient client = proxyClient.client(); try { // Ensure resource exists on the ECR Registry. if (!hasExistingResource(describeRegistryResource(proxy, client))) { throw new ResourceNotFoundException(ResourceModel.TYPE_NAME, model.getRegistryId()); } final PutReplicationConfigurationResponse response = proxy.injectCredentialsAndInvokeV2( Translator.putReplicationConfiguration(model), client::putReplicationConfiguration); logger.log(String.format("%s [%s] Update Successful", ResourceModel.TYPE_NAME, response.replicationConfiguration())); } catch (AwsServiceException e) { return ProgressEvent.builder() .resourceModel(model) .status(OperationStatus.FAILED) .errorCode(HandlerErrorCode.GeneralServiceException) .message(e.getMessage()) .build(); } return ProgressEvent.builder() .resourceModel(model) .status(OperationStatus.SUCCESS) .build(); } }