in aws-synthetics-canary/src/main/java/com/amazon/synthetics/canary/UpdateHandler.java [132:164]
private ProgressEvent<ResourceModel, CallbackContext> handleCanaryInStateRunning(Canary canary) {
log("Canary is in state RUNNING.");
if (context.getInitialCanaryState() == CanaryState.RUNNING) {
// If the canary was initially in state RUNNING and there was an error
// during provisioning, then it will be set to RUNNING again and the message
// will be in the StateReason field.
if (!Strings.isNullOrEmpty(canary.status().stateReason())) {
log(String.format("Update failed: %s", canary.status().stateReason()));
return ProgressEvent.failed(
model,
context,
HandlerErrorCode.GeneralServiceException,
canary.status().stateReason());
}
// If the canary was initially in state RUNNING and StartCanaryAfterCreation is
// false, we should stop the canary.
if (!model.getStartCanaryAfterCreation()) {
// There is a race condition here. We will get an exception if someone calls
// DeleteCanary, StopCanary, or UpdateCanary before we call StopCanary.
proxy.injectCredentialsAndInvokeV2(
StopCanaryRequest.builder()
.name(canary.name())
.build(),
syntheticsClient::stopCanary);
return waitingForCanaryStateTransition("Stopping canary", MAX_RETRY_TIMES, "RUNNING");
}
}
return ProgressEvent.defaultSuccessHandler(ModelHelper.constructModel(canary, model));
}