D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Utilisation createFleet avec un AWS SDK
Les exemples de code suivants illustrent comment utiliser createFleet.
Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :
- Java
-
- SDK pour Java 2.x
-
/**
* Creates a new fleet.
*
* @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
* @param fleetId the unique identifier for the fleet
* @return a {@link CompletableFuture} that completes with the ID of the created fleet
*/
public CompletableFuture<String> createFleetAsync(String catARN, String fleetId) {
CreateFleetRequest fleetRequest = CreateFleetRequest.builder()
.fleetId(fleetId)
.signalCatalogArn(catARN)
.description("Built using the AWS For Java V2")
.build();
CompletableFuture<String> result = new CompletableFuture<>();
getAsyncClient().createFleet(fleetRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause() != null ? exception.getCause() : exception;
if (cause instanceof ResourceNotFoundException) {
result.completeExceptionally(cause);
} else {
result.completeExceptionally(new RuntimeException("An unexpected error occurred", cause));
}
} else {
result.complete(response.id());
}
});
return result;
}
- Kotlin
-
- SDK pour Kotlin
-
/**
* Creates a new fleet.
*
* @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
* @param fleetId the unique identifier for the fleet
* @return the ID of the created fleet
*/
suspend fun createFleet(catARN: String, fleetIdVal: String): String {
val fleetRequest = CreateFleetRequest {
fleetId = fleetIdVal
signalCatalogArn = catARN
description = "Built using the AWS For Kotlin"
}
IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient ->
val response = fleetwiseClient.createFleet(fleetRequest)
return response.id
}
}