AWS IoT 1-Click Devices examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with AWS IoT 1-Click Devices.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use claim-devices-by-claim-code
.
- AWS CLI
-
To claim one or more AWS IoT 1-Click devices using a claim code
The following
claim-devices-by-claim-code
example claims the specified AWS IoT 1-Click device using a claim code (instead of a device ID).aws iot1click-devices claim-devices-by-claim-code \ --claim-code
C-123EXAMPLE
Output:
{ "Total": 9 "ClaimCode": "C-123EXAMPLE" }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see ClaimDevicesByClaimCode
in AWS CLI Command Reference.
-
The following code example shows how to use describe-device
.
- AWS CLI
-
To describe a device
The following
describe-device
example describes the specified device.aws iot1click-devices describe-device \ --device-id
G030PM0123456789
Output:
{ "DeviceDescription": { "Arn": "arn:aws:iot1click:us-west-2:012345678901:devices/G030PM0123456789", "Attributes": { "projectRegion": "us-west-2", "projectName": "AnytownDumpsters", "placementName": "customer217", "deviceTemplateName": "empty-dumpster-request" }, "DeviceId": "G030PM0123456789", "Enabled": false, "RemainingLife": 99.9, "Type": "button", "Tags": {} } }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see DescribeDevice
in AWS CLI Command Reference.
-
The following code example shows how to use finalize-device-claim
.
- AWS CLI
-
To finalize a claim request for an AWS IoT 1-Click device using a device ID
The following
finalize-device-claim
example finalizes a claim request for the specified AWS IoT 1-Click device using a device ID (instead of a claim code).aws iot1click-devices finalize-device-claim \ --device-id
G030PM0123456789
Output:
{ "State": "CLAIMED" }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see FinalizeDeviceClaim
in AWS CLI Command Reference.
-
The following code example shows how to use get-device-methods
.
- AWS CLI
-
To list the available methods for a device
The following
get-device-methods
example lists the available methods for a device.aws iot1click-devices get-device-methods \ --device-id
G030PM0123456789
Output:
{ "DeviceMethods": [ { "MethodName": "getDeviceHealthParameters" }, { "MethodName": "setDeviceHealthMonitorCallback" }, { "MethodName": "getDeviceHealthMonitorCallback" }, { "MethodName": "setOnClickCallback" }, { "MethodName": "getOnClickCallback" } ] }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see GetDeviceMethods
in AWS CLI Command Reference.
-
The following code example shows how to use initiate-device-claim
.
- AWS CLI
-
To initiate a claim request for an AWS IoT 1-Click device using a device ID
The following
initiate-device-claim
example initiates a claim request for the specified AWS IoT 1-Click device using a device ID (instead of a claim code).aws iot1click-devices initiate-device-claim \ --device-id
G030PM0123456789
Output:
{ "State": "CLAIM_INITIATED" }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see InitiateDeviceClaim
in AWS CLI Command Reference.
-
The following code example shows how to use invoke-device-method
.
- AWS CLI
-
To invoke a device method on a device
The following
invoke-device-method
example invokes the specified method on a device.aws iot1click-devices invoke-device-method \ --cli-input-json
file://invoke-device-method.json
Contents of
invoke-device-method.json
:{ "DeviceId": "G030PM0123456789", "DeviceMethod": { "DeviceType": "device", "MethodName": "getDeviceHealthParameters" } }
Output:
{ "DeviceMethodResponse": "{\"remainingLife\": 99.8}" }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see InvokeDeviceMethod
in AWS CLI Command Reference.
-
The following code example shows how to use list-device-events
.
- AWS CLI
-
To list a device's events for a specified time range
The following
list-device-events
example lists the specified device's events for the specified time range.aws iot1click-devices list-device-events \ --device-id
G030PM0123456789
\ --from-time-stamp2019-07-17T15:45:12.880Z
--to-time-stamp2019-07-19T15:45:12.880Z
Output:
{ "Events": [ { "Device": { "Attributes": {}, "DeviceId": "G030PM0123456789", "Type": "button" }, "StdEvent": "{\"clickType\": \"SINGLE\", \"reportedTime\": \"2019-07-18T23:47:55.015Z\", \"certificateId\": \"fe8798a6c97c62ef8756b80eeefdcf2280f3352f82faa8080c74cc4f4a4d1811\", \"remainingLife\": 99.85000000000001, \"testMode\": false}" }, { "Device": { "Attributes": {}, "DeviceId": "G030PM0123456789", "Type": "button" }, "StdEvent": "{\"clickType\": \"DOUBLE\", \"reportedTime\": \"2019-07-19T00:14:41.353Z\", \"certificateId\": \"fe8798a6c97c62ef8756b80eeefdcf2280f3352f82faa8080c74cc4f4a4d1811\", \"remainingLife\": 99.8, \"testMode\": false}" } ] }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see ListDeviceEvents
in AWS CLI Command Reference.
-
The following code example shows how to use list-devices
.
- AWS CLI
-
To list the devices of a specified type
The following
list-devices
example lists the devices of a specified type.aws iot1click-devices list-devices \ --device-type
button
This command produces no output.
Output:
{ "Devices": [ { "remainingLife": 99.9, "attributes": { "arn": "arn:aws:iot1click:us-west-2:123456789012:devices/G030PM0123456789", "type": "button", "deviceId": "G030PM0123456789", "enabled": false } } ] }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see ListDevices
in AWS CLI Command Reference.
-
The following code example shows how to use list-tags-for-resource
.
- AWS CLI
-
To list the tags for a device
The following
list-tags-for-resource
example list the tags for the specified device.aws iot1click-devices list-tags-for-resource \ --resource-arn
"arn:aws:iot1click:us-west-2:012345678901:devices/G030PM0123456789"
Output:
{ "Tags": { "Driver Phone": "123-555-0199", "Driver": "Jorge Souza" } }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see ListTagsForResource
in AWS CLI Command Reference.
-
The following code example shows how to use tag-resource
.
- AWS CLI
-
To add tags to a device AWS resource
The following
tag-resource
example adds two tags to the specified resource.aws iot1click-devices tag-resource \ --cli-input-json
file://devices-tag-resource.json
Contents of
devices-tag-resource.json
:{ "ResourceArn": "arn:aws:iot1click:us-west-2:123456789012:devices/G030PM0123456789", "Tags": { "Driver": "Jorge Souza", "Driver Phone": "123-555-0199" } }
This command produces no output.
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see TagResource
in AWS CLI Command Reference.
-
The following code example shows how to use unclaim-device
.
- AWS CLI
-
To unclaim (deregister) a device from your AWS account
The following
unclaim-device
example unclaims (deregisters) the specified device from your AWS account.aws iot1click-devices unclaim-device \ --device-id
G030PM0123456789
Output:
{ "State": "UNCLAIMED" }
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see UnclaimDevice
in AWS CLI Command Reference.
-
The following code example shows how to use untag-resource
.
- AWS CLI
-
To remove tags from a device AWS resource
The following
untag-resource
example removes the tags with the namesDriver Phone
andDriver
from the specified device resource.aws iot1click-devices untag-resource \ --resource-arn
"arn:aws:iot1click:us-west-2:123456789012:projects/AnytownDumpsters"
\ --tag-keys"Driver Phone"
"Driver"
This command produces no output.
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see UntagResource
in AWS CLI Command Reference.
-
The following code example shows how to use update-device-state
.
- AWS CLI
-
To update the ``enabled`` state for a device
The following
update-device-state
sets the state of the specified device toenabled
.aws iot1click-devices update-device-state \ --device-id
G030PM0123456789
\ --enabledThis command produces no output.
For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.
-
For API details, see UpdateDeviceState
in AWS CLI Command Reference.
-