Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use UpdateThing with an AWS SDK or CLI

Focus mode
Use UpdateThing with an AWS SDK or CLI - AWS IoT Core

The following code examples show how to use UpdateThing.

C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

//! Update an AWS IoT thing with attributes. /*! \param thingName: The name for the thing. \param attributeMap: A map of key/value attributes/ \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::updateThing(const Aws::String &thingName, const std::map<Aws::String, Aws::String> &attributeMap, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::UpdateThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::AttributePayload attributePayload; for (const auto &attribute: attributeMap) { attributePayload.AddAttributes(attribute.first, attribute.second); } request.SetAttributePayload(attributePayload); Aws::IoT::Model::UpdateThingOutcome outcome = iotClient.UpdateThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully updated thing " << thingName << std::endl; } else { std::cerr << "Failed to update thing " << thingName << ":" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • For API details, see UpdateThing in AWS SDK for C++ API Reference.

CLI
AWS CLI

To associate a thing with a thing type

The following update-thing example associates a thing in the AWS IoT registry with a thing type. When you make the association, you provide values for the attributes defined by the thing type.

aws iot update-thing \ --thing-name "MyOtherLightBulb" \ --thing-type-name "LightBulb" \ --attribute-payload "{"attributes": {"wattage":"75", "model":"123"}}"

This command does not produce output. Use the describe-thing command to see the result.

For more information, see Thing Types in the AWS IoT Developers Guide.

  • For API details, see UpdateThing in AWS CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Updates the shadow of an IoT Thing asynchronously. * * @param thingName The name of the IoT Thing. * * This method initiates an asynchronous request to update the shadow of an IoT Thing. * If the request is successful, it prints a confirmation message. * If an exception occurs, it prints the error message. */ public void updateShadowThing(String thingName) { // Create Thing Shadow State Document. String stateDocument = "{\"state\":{\"reported\":{\"temperature\":25, \"humidity\":50}}}"; SdkBytes data = SdkBytes.fromString(stateDocument, StandardCharsets.UTF_8); UpdateThingShadowRequest updateThingShadowRequest = UpdateThingShadowRequest.builder() .thingName(thingName) .payload(data) .build(); CompletableFuture<UpdateThingShadowResponse> future = getAsyncDataPlaneClient().updateThingShadow(updateThingShadowRequest); future.whenComplete((updateResponse, ex) -> { if (updateResponse != null) { System.out.println("Thing Shadow updated successfully."); } else { Throwable cause = ex != null ? ex.getCause() : null; if (cause instanceof IotException) { System.err.println(((IotException) cause).awsErrorDetails().errorMessage()); } else if (cause != null) { System.err.println("Unexpected error: " + cause.getMessage()); } else { System.err.println("Failed to update Thing Shadow."); } } }); future.join(); }
  • For API details, see UpdateThing in AWS SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun updateThing(thingNameVal: String?) { val newLocation = "Office" val newFirmwareVersion = "v2.0" val attMap: MutableMap<String, String> = HashMap() attMap["location"] = newLocation attMap["firmwareVersion"] = newFirmwareVersion val attributePayloadVal = AttributePayload { attributes = attMap } val updateThingRequest = UpdateThingRequest { thingName = thingNameVal attributePayload = attributePayloadVal } IotClient { region = "us-east-1" }.use { iotClient -> // Update the IoT thing attributes. iotClient.updateThing(updateThingRequest) println("$thingNameVal attributes updated successfully.") } }
  • For API details, see UpdateThing in AWS SDK for Kotlin API reference.

SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

//! Update an AWS IoT thing with attributes. /*! \param thingName: The name for the thing. \param attributeMap: A map of key/value attributes/ \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::updateThing(const Aws::String &thingName, const std::map<Aws::String, Aws::String> &attributeMap, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::UpdateThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::AttributePayload attributePayload; for (const auto &attribute: attributeMap) { attributePayload.AddAttributes(attribute.first, attribute.second); } request.SetAttributePayload(attributePayload); Aws::IoT::Model::UpdateThingOutcome outcome = iotClient.UpdateThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully updated thing " << thingName << std::endl; } else { std::cerr << "Failed to update thing " << thingName << ":" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • For API details, see UpdateThing in AWS SDK for C++ API Reference.

For a complete list of AWS SDK developer guides and code examples, see Using AWS IoT with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.