@@ -247,7 +247,7 @@ suspend fun deleteIoTThing(thingNameVal: String) {
247247 thingName = thingNameVal
248248 }
249249
250- IotClient { region = " us-east-1" }.use { iotClient ->
250+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
251251 iotClient.deleteThing(deleteThingRequest)
252252 println (" Deleted $thingNameVal " )
253253 }
@@ -260,7 +260,7 @@ suspend fun deleteCertificate(certificateArn: String) {
260260 DeleteCertificateRequest {
261261 certificateId = extractCertificateId(certificateArn)
262262 }
263- IotClient { region = " us-east-1" }.use { iotClient ->
263+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
264264 iotClient.deleteCertificate(certificateProviderRequest)
265265 println (" $certificateArn was successfully deleted." )
266266 }
@@ -285,7 +285,7 @@ suspend fun detachThingPrincipal(
285285 thingName = thingNameVal
286286 }
287287
288- IotClient { region = " us-east-1" }.use { iotClient ->
288+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
289289 iotClient.detachThingPrincipal(thingPrincipalRequest)
290290 println (" $certificateArn was successfully removed from $thingNameVal " )
291291 }
@@ -299,7 +299,7 @@ suspend fun searchThings(queryStringVal: String?) {
299299 queryString = queryStringVal
300300 }
301301
302- IotClient { region = " us-east-1" }.use { iotClient ->
302+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
303303 val searchIndexResponse = iotClient.searchIndex(searchIndexRequest)
304304 if (searchIndexResponse.things?.isEmpty() == true ) {
305305 println (" No things found." )
@@ -315,7 +315,7 @@ suspend fun searchThings(queryStringVal: String?) {
315315suspend fun listIoTRules () {
316316 val listTopicRulesRequest = ListTopicRulesRequest {}
317317
318- IotClient { region = " us-east-1" }.use { iotClient ->
318+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
319319 val listTopicRulesResponse = iotClient.listTopicRules(listTopicRulesRequest)
320320 println (" List of IoT rules:" )
321321 val ruleList = listTopicRulesResponse.rules
@@ -358,7 +358,7 @@ suspend fun createIoTRule(
358358 topicRulePayload = topicRulePayloadVal
359359 }
360360
361- IotClient { region = " us-east-1" }.use { iotClient ->
361+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
362362 iotClient.createTopicRule(topicRuleRequest)
363363 println (" IoT rule created successfully." )
364364 }
@@ -372,7 +372,7 @@ suspend fun getPayload(thingNameVal: String?) {
372372 thingName = thingNameVal
373373 }
374374
375- IotDataPlaneClient { region = " us-east-1" }.use { iotPlaneClient ->
375+ IotDataPlaneClient .fromEnvironment { region = " us-east-1" }.use { iotPlaneClient ->
376376 val getThingShadowResponse = iotPlaneClient.getThingShadow(getThingShadowRequest)
377377 val payload = getThingShadowResponse.payload
378378 val payloadString = payload?.let { java.lang.String (it, Charsets .UTF_8 ) }
@@ -383,7 +383,7 @@ suspend fun getPayload(thingNameVal: String?) {
383383
384384// snippet-start:[iot.kotlin.list.certs.main]
385385suspend fun listCertificates () {
386- IotClient { region = " us-east-1" }.use { iotClient ->
386+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
387387 val response = iotClient.listCertificates()
388388 val certList = response.certificates
389389 certList?.forEach { cert ->
@@ -397,7 +397,7 @@ suspend fun listCertificates() {
397397// snippet-start:[iot.kotlin.describe.endpoint.main]
398398suspend fun describeEndpoint (): String? {
399399 val request = DescribeEndpointRequest {}
400- IotClient { region = " us-east-1" }.use { iotClient ->
400+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
401401 val endpointResponse = iotClient.describeEndpoint(request)
402402 val endpointUrl: String? = endpointResponse.endpointAddress
403403 val exString: String = getValue(endpointUrl)
@@ -445,7 +445,7 @@ suspend fun updateThing(thingNameVal: String?) {
445445 attributePayload = attributePayloadVal
446446 }
447447
448- IotClient { region = " us-east-1" }.use { iotClient ->
448+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
449449 // Update the IoT thing attributes.
450450 iotClient.updateThing(updateThingRequest)
451451 println (" $thingNameVal attributes updated successfully." )
@@ -466,7 +466,7 @@ suspend fun updateShawdowThing(thingNameVal: String?) {
466466 payload = byteArray
467467 }
468468
469- IotDataPlaneClient { region = " us-east-1" }.use { iotPlaneClient ->
469+ IotDataPlaneClient .fromEnvironment { region = " us-east-1" }.use { iotPlaneClient ->
470470 iotPlaneClient.updateThingShadow(updateThingShadowRequest)
471471 println (" The thing shadow was updated successfully." )
472472 }
@@ -484,7 +484,7 @@ suspend fun attachCertificateToThing(
484484 principal = certificateArn
485485 }
486486
487- IotClient { region = " us-east-1" }.use { iotClient ->
487+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
488488 iotClient.attachThingPrincipal(principalRequest)
489489 println (" Certificate attached to $thingNameVal successfully." )
490490 }
@@ -499,7 +499,7 @@ suspend fun describeThing(thingNameVal: String) {
499499 }
500500
501501 // Print Thing details.
502- IotClient { region = " us-east-1" }.use { iotClient ->
502+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
503503 val describeResponse = iotClient.describeThing(thingRequest)
504504 println (" Thing details:" )
505505 println (" Thing name: ${describeResponse.thingName} " )
@@ -510,7 +510,7 @@ suspend fun describeThing(thingNameVal: String) {
510510
511511// snippet-start:[iot.kotlin.create.cert.main]
512512suspend fun createCertificate (): String? {
513- IotClient { region = " us-east-1" }.use { iotClient ->
513+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
514514 val response = iotClient.createKeysAndCertificate()
515515 val certificatePem = response.certificatePem
516516 val certificateArn = response.certificateArn
@@ -532,7 +532,7 @@ suspend fun createIoTThing(thingNameVal: String) {
532532 thingName = thingNameVal
533533 }
534534
535- IotClient { region = " us-east-1" }.use { iotClient ->
535+ IotClient .fromEnvironment { region = " us-east-1" }.use { iotClient ->
536536 iotClient.createThing(createThingRequest)
537537 println (" Created $thingNameVal }" )
538538 }
0 commit comments