Úselo DeleteThing con un AWS SDK o CLI - AWS IoT Core

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 DeleteThing con un AWS SDK o CLI

Los siguientes ejemplos de código muestran cómo utilizar DeleteThing.

.NET
SDK para .NET (v4)
nota

Hay más información GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Deletes an IoT Thing. /// </summary> /// <param name="thingName">The name of the Thing to delete.</param> /// <returns>True if successful, false otherwise.</returns> public async Task<bool> DeleteThingAsync(string thingName) { try { var request = new DeleteThingRequest { ThingName = thingName }; await _amazonIoT.DeleteThingAsync(request); _logger.LogInformation($"Deleted Thing {thingName}"); return true; } catch (Amazon.IoT.Model.ResourceNotFoundException ex) { _logger.LogError($"Cannot delete Thing - resource not found: {ex.Message}"); return false; } catch (Exception ex) { _logger.LogError($"Couldn't delete Thing. Here's why: {ex.Message}"); return false; } }
  • Para obtener más información sobre la API, consulta DeleteThingla Referencia AWS SDK para .NET de la API.

C++
SDK para C++
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

//! Delete an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteThingRequest request; request.SetThingName(thingName); const auto outcome = iotClient.DeleteThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted thing " << thingName << std::endl; } else { std::cerr << "Error deleting thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • Para obtener más información sobre la API, consulta DeleteThingla Referencia AWS SDK para C++ de la API.

CLI
AWS CLI

Para visualizar información detallada acerca de un objeto

En el siguiente delete-thing ejemplo, se elimina un elemento del registro de AWS IoT de tu AWS cuenta.

¿Fue para borrar algo --thing-name» FourthBulb

Este comando no genera ninguna salida.

Para obtener más información, consulte Administración de objetos con el registro en la Guía para desarrolladores de AWS IoT.

  • Para obtener más información sobre la API, consulte la Referencia de comandos. DeleteThingAWS CLI

Java
SDK para Java 2.x
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/** * Deletes an IoT Thing asynchronously. * * @param thingName The name of the IoT Thing to delete. * * This method initiates an asynchronous request to delete an IoT Thing. * If the deletion is successful, it prints a confirmation message. * If an exception occurs, it prints the error message. */ public void deleteIoTThing(String thingName) { DeleteThingRequest deleteThingRequest = DeleteThingRequest.builder() .thingName(thingName) .build(); CompletableFuture<DeleteThingResponse> future = getAsyncClient().deleteThing(deleteThingRequest); future.whenComplete((voidResult, ex) -> { if (ex == null) { System.out.println("Deleted Thing " + thingName); } else { Throwable cause = ex.getCause(); if (cause instanceof IotException) { System.err.println(((IotException) cause).awsErrorDetails().errorMessage()); } else { System.err.println("Unexpected error: " + ex.getMessage()); } } }); future.join(); }
  • Para obtener más información sobre la API, consulta DeleteThingla Referencia AWS SDK for Java 2.x de la API.

Kotlin
SDK para Kotlin
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

suspend fun deleteIoTThing(thingNameVal: String) { val deleteThingRequest = DeleteThingRequest { thingName = thingNameVal } IotClient.fromEnvironment { region = "us-east-1" }.use { iotClient -> iotClient.deleteThing(deleteThingRequest) println("Deleted $thingNameVal") } }
  • Para obtener más información sobre la API, consulta DeleteThingla referencia sobre el AWS SDK para la API de Kotlin.

Python
SDK para Python (Boto3)
nota

Hay más información al respecto. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

class IoTWrapper: """Encapsulates AWS IoT actions.""" def __init__(self, iot_client, iot_data_client=None): """ :param iot_client: A Boto3 AWS IoT client. :param iot_data_client: A Boto3 AWS IoT Data Plane client. """ self.iot_client = iot_client self.iot_data_client = iot_data_client @classmethod def from_client(cls): iot_client = boto3.client("iot") iot_data_client = boto3.client("iot-data") return cls(iot_client, iot_data_client) def delete_thing(self, thing_name): """ Deletes an AWS IoT thing. :param thing_name: The name of the thing to delete. """ try: self.iot_client.delete_thing(thingName=thing_name) logger.info("Deleted thing %s.", thing_name) except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Cannot delete thing. Resource not found.") return logger.error( "Couldn't delete thing. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • Para obtener más información sobre la API, consulta DeleteThingla AWS Referencia de API de SDK for Python (Boto3).

Para obtener una lista completa de las guías para desarrolladores del AWS SDK y ejemplos de código, consulte. Se utiliza AWS IoT con un SDK AWS En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.