Skip to content

Commit b7ba06e

Browse files
authored
Java V2 Updated IoT scenario (#6611)
1 parent 28954d1 commit b7ba06e

File tree

17 files changed

+1070
-707
lines changed

17 files changed

+1070
-707
lines changed

.doc_gen/metadata/iot_metadata.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ iot_CreateKeysAndCertificate:
124124
excerpts:
125125
- description:
126126
snippet_tags:
127-
- iot.java2.create.cert.main
127+
- iot.kotlin.create.cert.main
128128
Java:
129129
versions:
130130
- sdk_version: 2
@@ -347,7 +347,7 @@ iot_UpdateThing:
347347
excerpts:
348348
- description:
349349
snippet_tags:
350-
- iot.java2.update.thing.main
350+
- iot.java2.update.shadow.thing.main
351351
C++:
352352
versions:
353353
- sdk_version: 1
@@ -449,9 +449,12 @@ iot_Scenario:
449449
github: javav2/example_code/iot
450450
sdkguide:
451451
excerpts:
452-
- description:
452+
- description: Run an interactive scenario demonstrating &IoT; features.
453453
snippet_tags:
454454
- iot.java2.scenario.main
455+
- description: A wrapper class for &IoT; SDK methods.
456+
snippet_tags:
457+
- iot.java2.scenario.actions.main
455458
C++:
456459
versions:
457460
- sdk_version: 1

basics_scenarios/iot_scenario/README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# AWS IoT Getting Started Scenario
1+
# AWS IoT Basics Scenario
22

33
## Introduction
4-
This Java-based AWS IoT program demonstrates a getting started scenario for interacting with the AWS IoT Core service. The program guides you through a series of steps, including creating an IoT Thing, generating a device certificate, updating the Thing with attributes, and performing various other operations. It utilizes the AWS SDK for Java V2 and showcases the functionality for managing IoT Things, certificates, rules, shadows, and performing searches. Furthermore, this example covers a wide range of functionality for new users of the Java SDK and AWS IoT Core service.
4+
The AWS IoT basics scenario demonstrates how to interact with the AWS IoT Core service. The program guides you through a series of steps, including creating an IoT Thing, generating a device certificate, updating the Thing with attributes, and performing various other operations. It utilizes the AWS SDK and showcases the functionality for managing IoT Things, certificates, rules, shadows, and performing searches. Furthermore, this example covers a wide range of functionality for new users of the AWS SDK and AWS IoT Core service.
55

66
## User Interaction
77
The program prompts the user for input at various stages, allowing them to customize the scenario to their specific needs. The user is asked to provide the following information:
@@ -15,25 +15,17 @@ The program prompts the user for input at various stages, allowing them to custo
1515

1616
Throughout the workflow, the program provides detailed explanations and prompts the user to press Enter to continue, ensuring a user-friendly experience.
1717

18-
## Service Operations Invoked
19-
The program interacts with the following AWS IoT service operations:
20-
21-
1. **createThing**: Creates a new IoT Thing in the AWS IoT Core service.
22-
2. **createKeysAndCertificate**: Generates a new device certificate and its associated private key.
23-
3. **attachThingPrincipal**: Attaches the generated device certificate to the IoT Thing.
24-
4. **updateThingShadow**: Updates the IoT Thing with new attributes.
25-
5. **describeEndpoint**: Retrieves the unique endpoint specific to the user's AWS account.
26-
6. **listCertificates**: Lists the user's existing IoT certificates.
27-
7. **updateThingShadow**: Updates the digital representation (shadow) of the IoT Thing.
28-
8. **getThingShadow**: Retrieves the state information of the IoT Thing's shadow in JSON format.
29-
9. **createTopicRule**: Creates a new rule that triggers an SNS action based on a SQL query.
30-
10. **listTopicRules**: Lists the user's existing IoT rules.
31-
11. **searchIndex**: Performs a search for IoT Things based on the provided query string.
32-
12. **detachThingPrincipal**: Detaches the device certificate from the IoT Thing.
33-
13. **deleteCertificate**: Deletes the previously created device certificate.
34-
14. **deleteThing**: Deletes the IoT Thing.
35-
36-
The program demonstrates the comprehensive capabilities of the AWS IoT Core service and showcases how to integrate these various operations using the AWS SDK for Java V2.
18+
## Implementations
19+
20+
This scenario example is implemented in the following languages:
21+
22+
- Java
23+
- C++
24+
- Kotlin
25+
26+
## Additional reading
27+
28+
- [AWS IoT](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html)
3729

3830

3931

basics_scenarios/iot_scenario/SPECIFICATION.md

Lines changed: 87 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,76 @@
1-
# Performing device management use cases using the AWS Iot SDK technical specification
1+
# AWS Iot SDK Basic Scenario Technical Specification
22

33
## Overview
44
This example shows how to use AWS SDKs to perform device management use cases using the AWS Iot SDK.
55

66
The AWS Iot API provides secure, bi-directional communication between Internet-connected devices (such as sensors, actuators, embedded devices, or smart appliances) and the Amazon Web Services cloud. This example shows some typical use cases such as creating things, creating certifications, applying the certifications to the IoT Thing and so on.
77

8-
The IotClient service client is used in this example and the following service operations are covered:
9-
10-
1. Creates an AWS IoT Thing using the createThing().
11-
2. Generate a device certificate using the createKeysAndCertificate().
12-
3. Attach the certificate to the AWS IoT Thing using attachThingPrincipal().
13-
4. Update an AWS IoT Thing with Attributes using updateThingShadow().
14-
5. Get an AWS IoT Endpoint using describeEndpoint().
15-
6. List your certificates using listCertificates().
16-
7. Detach and delete the certificate from the AWS IoT thing.
17-
8. Updates the shadow for the specified thing.
18-
9. Write out the state information, in JSON format.
19-
10. Creates a rule
20-
11. List rules
21-
12. Search things
22-
13. Delete Thing.
8+
## Resources
9+
This program requires these AWS resources.
10+
11+
1. **roleARN** - The ARN of an IAM role that has permission to work with AWS IOT.
12+
2. **snsAction** - An ARN of an SNS topic.
13+
14+
## Hello AWS IoT
15+
16+
This program is intended for users not familiar with the Amazon IoT SDK to easily get up and running. The logic is to show use of `listThingsPaginator`.
17+
18+
## Scenario Program Flow
19+
20+
This scenario demonstrates the following key AWS IoT Service operations:
21+
22+
1. **Create an AWS IoT Thing**:
23+
- Use the `CreateThing` API to create a new AWS IoT Thing.
24+
- Specify the Thing name and any desired Thing attributes.
25+
26+
2. **Generate a Device Certificate**:
27+
- Use the `CreateKeysAndCertificate` API to generate a new device certificate.
28+
- The certificate is used to authenticate the device when connecting to AWS IoT.
29+
30+
3. **Attach the Certificate to the AWS IoT Thing**:
31+
- Use the `AttachThingPrincipal` API to associate the device certificate with the AWS IoT Thing.
32+
- This allows the device to authenticate and communicate with the AWS IoT Core service.
33+
34+
4. **Update an AWS IoT Thing with Attributes**:
35+
- Use the `UpdateThingShadow` API to update the Thing's shadow with new attribute values.
36+
- The Thing's shadow represents the device's state and properties.
37+
38+
5. **Get an AWS IoT Endpoint**:
39+
- Use the `DescribeEndpoint` API to retrieve the AWS IoT Core service endpoint.
40+
- The device uses this endpoint to connect and communicate with AWS IoT.
41+
42+
6. **List Certificates**:
43+
- Use the `ListCertificates` API to retrieve a list of all certificates associated with the AWS IoT account.
44+
45+
7. **Detach and Delete the Certificate**:
46+
- Use the `DetachThingPrincipal` API to detach the certificate from the AWS IoT Thing.
47+
- Use the `DeleteCertificate` API to delete the certificate.
48+
49+
8. **Update the Thing Shadow**:
50+
- Use the `UpdateThingShadow` API to update the Thing's shadow with new state information.
51+
- The Thing's shadow represents the device's state and properties.
52+
53+
9. **Write State Information in JSON Format**:
54+
- The state information is written in JSON format, which is the standard data format used by AWS IoT.
55+
56+
10. **Create an AWS IoT Rule**:
57+
- Use the `CreateTopicRule` API to create a new AWS IoT Rule.
58+
- Rules allow you to define actions to be performed based on device data or events.
59+
60+
11. **List AWS IoT Rules**:
61+
- Use the `ListTopicRules` API to retrieve a list of all AWS IoT Rules.
62+
63+
12. **Search AWS IoT Things**:
64+
- Use the `SearchThings` API to search for AWS IoT Things based on various criteria, such as Thing name, attributes, or shadow state.
65+
66+
13. **Delete an AWS IoT Thing**:
67+
- Use the `DeleteThing` API to delete an AWS IoT Thing.
2368

2469
Note: We have buy off on these operations from IoT SME.
2570

26-
### Application Output
71+
### Program execution
2772

28-
This Workflow does have user interaction. The following shows the output of the Java V2 program.
73+
This scenario does have user interaction. The following shows the output of the program.
2974

3075
```
3176
--------------------------------------------------------------------------------
@@ -55,23 +100,7 @@ Do you want to create a certificate for foo5543? (y/n)y
55100
Certificate:
56101
-----BEGIN CERTIFICATE-----
57102
MIIDWTCCAkGgAwIBAgIUY3PjIZIcFhCrPuBvH16219CPqD0wDQYJKoZIhvcNAQEL
58-
BQAwTTFLMEkGA1UECwxCQW1hem9uIFdlYiBTZXJ2aWNlcyBPPUFtYXpvbi5jb20g
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y8o3Gj2NEK6Mlb7ZpLvl2p
103+
BQAwTTFLMEkGA1UECwxCQW1hem9uIFdlYiBTZXJ2aWNlcy
75104
-----END CERTIFICATE-----
76105
77106
@@ -169,5 +198,27 @@ Deleted Thing foo5543
169198
--------------------------------------------------------------------------------
170199
The AWS IoT workflow has successfully completed.
171200
--------------------------------------------------------------------------------
201+
```
172202

173-
Process finished with exit code 0
203+
## SOS Tags
204+
205+
The following table describes the metadata used in this scenario.
206+
207+
208+
| action | metadata file | metadata key |
209+
|------------------------------|------------------------------|---------------------------------------- |
210+
| `describeEndpoint` | iot_metadata.yaml | iot_DescribeEndpoint |
211+
| `listThings` | iot_metadata.yaml | iot_ListThings |
212+
| `listCertificates` | iot_metadata.yaml | iot_ListCertificates |
213+
| `CreateKeysAndCertificate` | iot_metadata.yaml | iot_CreateKeysAndCertificate |
214+
| `deleteCertificate` | iot_metadata.yaml | iot_DeleteCertificate |
215+
| `searchIndex` | iot_metadata.yaml | iot_SearchIndex |
216+
| `deleteThing` | iot_metadata.yaml | iot_DeleteThing |
217+
| `describeThing` | iot_metadata.yaml | iot_DescribeThing |
218+
| `attachThingPrincipal` | iot_metadata.yaml | iot_AttachThingPrincipal |
219+
| `detachThingPrincipal` | iot_metadata.yaml | iot_DetachThingPrincipal |
220+
| `updateThing` | iot_metadata.yaml | iot_UpdateThing |
221+
| `createTopicRule` | iot_metadata.yaml | iot_CreateTopicRule |
222+
| `createThing` | iot_metadata.yaml | iot_CreateThing |
223+
| `hello ` | iot_metadata.yaml | iot_Hello |
224+
| `scenario | iot_metadata.yaml | iot_Scenario |

javav2/example_code/iot/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav
3838

3939
Code excerpts that show you how to call individual service functions.
4040

41-
- [AttachThingPrincipal](src/main/java/com/example/iot/IotScenario.java#L481)
42-
- [CreateKeysAndCertificate](src/main/java/com/example/iot/IotScenario.java#L458)
43-
- [CreateThing](src/main/java/com/example/iot/IotScenario.java#L541)
44-
- [CreateTopicRule](src/main/java/com/example/iot/IotScenario.java#L289)
45-
- [DeleteCertificate](src/main/java/com/example/iot/IotScenario.java#L439)
46-
- [DeleteThing](src/main/java/com/example/iot/IotScenario.java#L524)
47-
- [DescribeEndpoint](src/main/java/com/example/iot/IotScenario.java#L400)
48-
- [DescribeThing](src/main/java/com/example/iot/IotScenario.java#L504)
49-
- [DetachThingPrincipal](src/main/java/com/example/iot/IotScenario.java#L421)
50-
- [ListCertificates](src/main/java/com/example/iot/IotScenario.java#L258)
51-
- [SearchIndex](src/main/java/com/example/iot/IotScenario.java#L577)
52-
- [UpdateThing](src/main/java/com/example/iot/IotScenario.java#L369)
41+
- [AttachThingPrincipal](src/main/java/com/example/iot/scenario/IotActions.java#L191)
42+
- [CreateKeysAndCertificate](src/main/java/com/example/iot/scenario/IotActions.java#L119)
43+
- [CreateThing](src/main/java/com/example/iot/scenario/IotActions.java#L158)
44+
- [CreateTopicRule](src/main/java/com/example/iot/scenario/IotActions.java#L441)
45+
- [DeleteCertificate](src/main/java/com/example/iot/scenario/IotActions.java#L609)
46+
- [DeleteThing](src/main/java/com/example/iot/scenario/IotActions.java#L642)
47+
- [DescribeEndpoint](src/main/java/com/example/iot/scenario/IotActions.java#L308)
48+
- [DescribeThing](src/main/java/com/example/iot/scenario/IotActions.java#L232)
49+
- [DetachThingPrincipal](src/main/java/com/example/iot/scenario/IotActions.java#L574)
50+
- [ListCertificates](src/main/java/com/example/iot/scenario/IotActions.java#L370)
51+
- [SearchIndex](src/main/java/com/example/iot/scenario/IotActions.java#L533)
52+
- [UpdateThing](src/main/java/com/example/iot/scenario/IotActions.java#L269)
5353

5454
### Scenarios
5555

5656
Code examples that show you how to accomplish a specific task by calling multiple
5757
functions within the same service.
5858

59-
- [Work with device management use cases](src/main/java/com/example/iot/IotScenario.java)
59+
- [Work with device management use cases](src/main/java/com/example/iot/scenario/IotScenario.java)
6060

6161

6262
<!--custom.examples.start-->

0 commit comments

Comments
 (0)