I seem to be unable to find the Kotlin SDK for AWS IOT.
I searched the internet and I can find Kotlin SDKs for other Amazon services, and AWS IOT code examples for Java and other languages, but there doesn't seem to be any Kotlin examples for AWS IOT. Am I missing something? Is there really no IOT SDK for Kotlin?
The new AWS SDK for Kotlin does expose an IOT API. You can find the Kotlin API Reference docs here:
https://sdk.amazonaws.com/kotlin/api/latest/iot/aws.sdk.kotlin.services.iot/-iot-client/index.html
The Kotlin SDK Dev Guide can be found here:
What is the AWS SDK for Kotlin?
However, at the current time, there are no examples for this API in the Kotlin section of the AWS Code Lib.
Here is a getting started code example that uses the Kotlin SDK.
package com.example.iot
import aws.sdk.kotlin.services.iot.IotClient
import aws.sdk.kotlin.services.iot.model.ListThingsRequest
suspend fun main() {
println("Hello AWS IoT. Here is a listing of your AWS IoT Things:")
listAllThings()
}
suspend fun listAllThings() {
val thingsRequest = ListThingsRequest {
maxResults = 10
}
IotClient { region = "us-east-1" }.use { iotClient ->
val response = iotClient.listThings(thingsRequest)
val thingList = response.things
if (thingList != null) {
for (attribute in thingList) {
println("Thing name ${attribute.thingName}")
println("Thing ARN: ${attribute.thingArn}")
}
}
}
}