/** * Delete a NAT Gateway * It waits for the NAT gateway to get into the Deleted state before returning. */ public DeferredResult<Void> deleteNATGateway(String natGatewayId, TaskManager taskManager, long taskExpirationMicros) { DeleteNatGatewayRequest req = new DeleteNatGatewayRequest() .withNatGatewayId(natGatewayId); String message = "Delete AWS NAT Gateway with id [" + natGatewayId + "]."; AWSDeferredResultAsyncHandler<DeleteNatGatewayRequest, DeleteNatGatewayResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message); this.client.deleteNatGatewayAsync(req, handler); return handler.toDeferredResult() .thenCompose(ignore -> waitForNatGatewayState(natGatewayId, taskManager, taskExpirationMicros, AWSTaskStatusChecker.AWS_DELETED_NAME)) .thenApply(ignore -> null); }
public void deleteNATGateway(String gatewayId) { logger.info("delete nat gateway, natGatewayId={}", gatewayId); AWS.vpc.ec2.deleteNatGateway(new DeleteNatGatewayRequest().withNatGatewayId(gatewayId)); while (true) { Threads.sleepRoughly(Duration.ofSeconds(30)); NatGateway gateway = AWS.vpc.describeNATGateway(gatewayId); String state = gateway.getState(); if ("deleting".equals(state)) continue; if ("deleted".equals(state)) { break; } else { throw new Error("failed to delete nat gateway, gatewayId=" + gatewayId + ", state=" + state); } } }
@Override public DeleteNatGatewayResult deleteNatGateway(DeleteNatGatewayRequest deleteNatGatewayRequest) { throw new UnsupportedOperationException("Not supported in mock"); }