Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK.
Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
Úselo DeleteMap con un SDK AWS
Los siguientes ejemplos de código muestran cómo utilizar DeleteMap.
Los ejemplos de acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Puede ver esta acción en contexto en el siguiente ejemplo de código:
- Java
-
- SDK para Java 2.x
-
/**
* Deletes a map with the specified name.
*
* @param mapName the name of the map to be deleted
* @return a {@link CompletableFuture} that completes when the map deletion is successful, or throws a {@link CompletionException} if an error occurs
*/
public CompletableFuture<Void> deleteMap(String mapName) {
DeleteMapRequest mapRequest = DeleteMapRequest.builder()
.mapName(mapName)
.build();
return getClient().deleteMap(mapRequest)
.whenComplete((response, exception) -> {
if (exception != null) {
Throwable cause = exception.getCause();
if (cause instanceof ResourceNotFoundException) {
throw new CompletionException("The map was not found.", cause);
}
throw new CompletionException("Failed to delete map: " + exception.getMessage(), exception);
}
logger.info("The map {} was deleted.", mapName);
})
.thenApply(response -> null);
}
- JavaScript
-
- SDK para JavaScript (v3)
-
import { fileURLToPath } from "node:url";
import {
DeleteMapCommand,
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 deleteMapParams = {
MapName: `${data.inputs.mapName}`,
};
try {
const locationClient = new LocationClient({ region: region });
const command = new DeleteMapCommand(deleteMapParams);
const response = await locationClient.send(command);
console.log("Map deleted.");
} catch (caught) {
if (caught instanceof ResourceNotFoundException) {
console.error(`${data.inputs.mapName} map not found.`);
return;
}
}
};
- Kotlin
-
- SDK para Kotlin
-
/**
* Deletes the specified key from the key-value store.
*
* @param keyName the name of the key to be deleted
*/
suspend fun deleteMap(mapName: String) {
val mapRequest = DeleteMapRequest {
this.mapName = mapName
}
LocationClient.fromEnvironment { region = "us-east-1" }.use { client ->
client.deleteMap(mapRequest)
println("The map $mapName was deleted.")
}
}