@Override
    protected void pulsate(ServiceInstance instance, HealthStatus status) {
        // this only work if you create a health status check when you register it
        // we can't really pulsate anywhere because amazon health checks work inverse from this UNLESS you have a custom health check
        Optional<String> opt = instance.getInstanceId();
        if (!opt.isPresent()) {
            // try the metadata
            if (instance.getMetadata().contains("instanceId")) {
                opt = Optional.of(instance.getMetadata().asMap().get("instanceId"));
            } else {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Cannot determine the instance ID. Are you sure you are running on AWS EC2?");
                }
            }
        }

        opt.ifPresent(instanceId -> {
            if (discoveryService != null && discoveryService.getHealthCheckCustomConfig() != null) {
                CustomHealthStatus customHealthStatus = CustomHealthStatus.UNHEALTHY;

                if (status.getOperational().isPresent()) {
                    customHealthStatus = CustomHealthStatus.HEALTHY;
                }

                UpdateInstanceCustomHealthStatusRequest updateInstanceCustomHealthStatusRequest = new UpdateInstanceCustomHealthStatusRequest()
                                                                                                            .withInstanceId(instanceId)
                                                                                                            .withServiceId(route53AutoRegistrationConfiguration.getAwsServiceId())
                                                                                                            .withStatus(customHealthStatus);
                getDiscoveryClient().updateInstanceCustomHealthStatus(
                        updateInstanceCustomHealthStatusRequest);
            }

            if (status.getOperational().isPresent() && !status.getOperational().get()) {
                getDiscoveryClient().deregisterInstance(new DeregisterInstanceRequest().withInstanceId(instanceId).withServiceId(route53AutoRegistrationConfiguration.getAwsServiceId()));
                LOG.info("Health status is non operational, instance id " + instanceId + " was de-registered from the discovery service.");
            }

        });

    }
@ Override protected void pulsate ( ServiceInstance instance , HealthStatus status ) { Optional < String > opt = instance . getInstanceId ( ) ; if ( ! opt . isPresent ( ) ) { if ( instance . getMetadata ( ) . contains ( "instanceId" ) ) { opt = Optional . of ( instance . getMetadata ( ) . asMap ( ) . get ( "instanceId" ) ) ; } else { if ( LOG . isErrorEnabled ( ) ) { LOG . error ( "Cannot determine the instance ID. Are you sure you are running on AWS EC2?" ) ; } } } opt . ifPresent ( instanceId -> { if ( discoveryService != null && discoveryService . getHealthCheckCustomConfig ( ) != null ) { CustomHealthStatus customHealthStatus = CustomHealthStatus . UNHEALTHY ; if ( status . getOperational ( ) . isPresent ( ) ) { customHealthStatus = CustomHealthStatus . HEALTHY ; } UpdateInstanceCustomHealthStatusRequest updateInstanceCustomHealthStatusRequest = new UpdateInstanceCustomHealthStatusRequest ( ) . withInstanceId ( instanceId ) . withServiceId ( route53AutoRegistrationConfiguration . getAwsServiceId ( ) ) . withStatus ( customHealthStatus ) ; getDiscoveryClient ( ) . updateInstanceCustomHealthStatus ( updateInstanceCustomHealthStatusRequest ) ; } if ( status . getOperational ( ) . isPresent ( ) && ! status . getOperational ( ) . get ( ) ) { getDiscoveryClient ( ) . deregisterInstance ( new DeregisterInstanceRequest ( ) . withInstanceId ( instanceId ) . withServiceId ( route53AutoRegistrationConfiguration . getAwsServiceId ( ) ) ) ; LOG . info ( "Health status is non operational, instance id " + instanceId + " was de-registered from the discovery service." ) ; } } ) ; }
If custom health check is enabled, this sends a heartbeat to it.
In most cases aws monitoring works off polling an application's endpoint
@param instance The instance of the service
@param status   The {@link HealthStatus}