D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples
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 CreateSchemaMapping
avec un AWS SDK
L'exemple de code suivant montre comment utiliserCreateSchemaMapping
.
- SDK pour Java 2.x
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. /** * Creates a schema mapping asynchronously. * * @param schemaName the name of the schema to create * @return a {@link CompletableFuture} that represents the asynchronous creation of the schema mapping */ public CompletableFuture<CreateSchemaMappingResponse> createSchemaMappingAsync(String schemaName) { List<SchemaInputAttribute> schemaAttributes = null; if (schemaName.startsWith("json")) { schemaAttributes = List.of( SchemaInputAttribute.builder().matchKey("id").fieldName("id").type(SchemaAttributeType.UNIQUE_ID).build(), SchemaInputAttribute.builder().matchKey("name").fieldName("name").type(SchemaAttributeType.NAME).build(), SchemaInputAttribute.builder().matchKey("email").fieldName("email").type(SchemaAttributeType.EMAIL_ADDRESS).build() ); } else { schemaAttributes = List.of( SchemaInputAttribute.builder().matchKey("id").fieldName("id").type(SchemaAttributeType.UNIQUE_ID).build(), SchemaInputAttribute.builder().matchKey("name").fieldName("name").type(SchemaAttributeType.NAME).build(), SchemaInputAttribute.builder().matchKey("email").fieldName("email").type(SchemaAttributeType.EMAIL_ADDRESS).build(), SchemaInputAttribute.builder().fieldName("phone").type(SchemaAttributeType.PROVIDER_ID).subType("STRING").build() ); } CreateSchemaMappingRequest request = CreateSchemaMappingRequest.builder() .schemaName(schemaName) .mappedInputFields(schemaAttributes) .build(); return getResolutionAsyncClient().createSchemaMapping(request) .whenComplete((response, exception) -> { if (response != null) { logger.info("[{}] schema mapping Created Successfully!", schemaName); } else { if (exception == null) { throw new CompletionException("An unknown error occurred while creating the schema mapping.", null); } Throwable cause = exception.getCause(); if (cause instanceof ConflictException) { throw new CompletionException("A conflicting schema mapping already exists. Resolve conflicts before proceeding.", cause); } // Wrap other AWS exceptions in a CompletionException. throw new CompletionException("Failed to create schema mapping: " + exception.getMessage(), exception); } }); }
-
Pour plus de détails sur l'API, reportez-vous CreateSchemaMappingà la section Référence des AWS SDK for Java 2.x API.
-