Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare deleteVehicle con un SDK AWS
Gli esempi di codice seguenti mostrano come utilizzare deleteVehicle.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- Java
-
- SDK per Java 2.x
-
/**
* Deletes a vehicle with the specified name.
*
* @param vecName the name of the vehicle to be deleted
* @return a {@link CompletableFuture} that completes when the vehicle has been deleted
*/
public CompletableFuture<Void> deleteVehicleAsync(String vecName) {
DeleteVehicleRequest request = DeleteVehicleRequest.builder()
.vehicleName(vecName)
.build();
return getAsyncClient().deleteVehicle(request)
.handle((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause() != null ? exception.getCause() : exception;
if (cause instanceof ResourceNotFoundException) {
throw (ResourceNotFoundException) cause;
}
throw new RuntimeException("Failed to delete the vehicle: " + cause);
}
return null;
});
}
- Kotlin
-
- SDK per Kotlin
-
suspend fun deleteVehicle(vecName: String) {
val request = DeleteVehicleRequest {
vehicleName = vecName
}
IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient ->
fleetwiseClient.deleteVehicle(request)
println("Vehicle $vecName was deleted successfully.")
}
}