Sono disponibili altri esempi di 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à.
Da utilizzare con un DeleteRouteCalculator AWS SDK
Gli esempi di codice seguenti mostrano come utilizzare DeleteRouteCalculator.
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 route calculator from the system.
*
* @param calcName the name of the route calculator to delete
* @return a {@link CompletableFuture} that completes when the route calculator has been deleted
* @throws CompletionException if an error occurs while deleting the route calculator
* - If the route calculator was not found, a {@link ResourceNotFoundException} will be thrown
* - If any other error occurs, a generic {@link CompletionException} will be thrown
*/
public CompletableFuture<Void> deleteRouteCalculator(String calcName) {
DeleteRouteCalculatorRequest calculatorRequest = DeleteRouteCalculatorRequest.builder()
.calculatorName(calcName)
.build();
return getClient().deleteRouteCalculator(calculatorRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause();
if (cause instanceof ResourceNotFoundException) {
throw new CompletionException("The route calculator was not found.", cause);
}
throw new CompletionException("Failed to delete the route calculator: " + exception.getMessage(), exception);
}
logger.info("The route calculator {} was deleted.", calcName);
})
.thenApply(response -> null);
}
- JavaScript
-
- SDK per JavaScript (v3)
-
import { fileURLToPath } from "node:url";
import {
DeleteRouteCalculatorCommand,
LocationClient,
ResourceNotFoundException,
} from "@aws-sdk/client-location";
import data from "./inputs.json" with { type: "json" };
const region = "eu-west-1";
export const main = async () => {
const deleteRouteCalculatorParams = {
CalculatorName: `${data.inputs.calculatorName}`,
};
try {
const locationClient = new LocationClient({ region: region });
const command = new DeleteRouteCalculatorCommand(
deleteRouteCalculatorParams,
);
const response = await locationClient.send(command);
console.log("Route calculator deleted.");
} catch (caught) {
if (caught instanceof ResourceNotFoundException) {
console.error(
`${data.inputs.calculatorName} route calculator not found.`,
);
return;
}
}
};
- Kotlin
-
- SDK per Kotlin
-
/**
* Deletes a route calculator from the system.
* @param calcName the name of the route calculator to delete
*/
suspend fun deleteRouteCalculator(calcName: String) {
val calculatorRequest = DeleteRouteCalculatorRequest {
this.calculatorName = calcName
}
LocationClient.fromEnvironment { region = "us-east-1" }.use { client ->
client.deleteRouteCalculator(calculatorRequest)
println("The route calculator $calcName was deleted.")
}
}