in aws-timestream-database/src/main/java/software/amazon/timestream/database/UpdateHandler.java [56:131]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final Logger logger) {
timestreamClient = TimestreamClientFactory.get(proxy, logger);
this.proxy = proxy;
final ResourceModel model = request.getDesiredResourceState();
final ResourceModel existingModel = request.getPreviousResourceState();
// Step 1: Update the DB with the new KMS CMK.
if (!StringUtils.equals(model.getKmsKeyId(), existingModel.getKmsKeyId())) {
try {
final UpdateDatabaseRequest updateDatabaseRequest =
new UpdateDatabaseRequest()
.withDatabaseName(model.getDatabaseName())
.withKmsKeyId(model.getKmsKeyId());
this.proxy.injectCredentialsAndInvoke(updateDatabaseRequest, timestreamClient::updateDatabase);
} catch (InternalServerException ex) {
throw new CfnInternalFailureException(ex);
} catch (ThrottlingException ex) {
throw new CfnThrottlingException(UPDATE_DATABASE, ex);
} catch (ValidationException | InvalidEndpointException ex) {
throw new CfnInvalidRequestException(request.toString(), ex);
} catch (ResourceNotFoundException ex) {
throw new CfnNotFoundException(ex);
} catch (AccessDeniedException ex) {
throw new CfnAccessDeniedException(UPDATE_DATABASE, ex);
} catch (ServiceQuotaExceededException ex) {
throw new CfnServiceLimitExceededException(ResourceModel.TYPE_NAME, QUOTE_MESSAGE, ex);
}
}
// Step 2: Update the tags
final Map<String, String> desiredTags = TagHelper.getNewDesiredTags(model, request);
final Map<String, String> previousTags = TagHelper.getPreviouslyAttachedTags(request);
final Set<Tag> tagsToAdd = TagHelper.convertToSet(
TagHelper.generateTagsToAdd(previousTags, desiredTags));
final Set<String> tagsToRemove = TagHelper.generateTagsToRemove(previousTags, desiredTags);
try {
final DescribeDatabaseRequest describeDatabaseRequest =
new DescribeDatabaseRequest().withDatabaseName(model.getDatabaseName());
final DescribeDatabaseResult describeDatabaseResult =
this.proxy.injectCredentialsAndInvoke(describeDatabaseRequest, timestreamClient::describeDatabase);
/*
* Update tags
*
* Here we first remove the tags no long exist, this includes tags whose values are modified.
* New tags are added afterwards, including tags with updated values.
*/
removeTags(describeDatabaseResult.getDatabase().getArn(), tagsToRemove);
addTags(describeDatabaseResult.getDatabase().getArn(), tagsToAdd);
} catch (InternalServerException ex) {
throw new CfnInternalFailureException(ex);
} catch (ThrottlingException ex) {
throw new CfnThrottlingException(UPDATE_DATABASE, ex);
} catch (ValidationException | InvalidEndpointException ex) {
throw new CfnInvalidRequestException(request.toString(), ex);
} catch (ResourceNotFoundException ex) {
throw new CfnNotFoundException(ex);
} catch (AccessDeniedException ex) {
throw new CfnAccessDeniedException(UPDATE_DATABASE, ex);
}
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.SUCCESS)
.build();
}