Skip to content

Commit

Permalink
Java v2 Add AWS IoT files (#6087)
Browse files Browse the repository at this point in the history
* add Java v2 IoT files

* add Java v2 IoT files

* updated spec

* updated readme

* updated readme

* updated readme

* updated yaml

* updated readme

* updated readme

* updated readme

* updated readme

* updated readme

* updated sos

* updated sos

* updated readme

* updated readme

* updated readme

* updated readme

* updated java file

* updated sos

* updated sos

* updated sos

* updated sos

* updated sos

* updated sos

* rolled in comments

* rolled in comments

* rolled in comments

* rolled in comments

* rolled in comments

* rolled in comments

* rolled in comments
  • Loading branch information
scmacdon authored Feb 13, 2024
1 parent e60abdb commit b532be1
Show file tree
Hide file tree
Showing 11 changed files with 1,509 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .doc_gen/metadata/iot-data_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# zexi 0.4.0
iot-data-plane_GetThingShadow:
title: Get the shadow for the specified thing using an &AWS; SDK
title_abbrev: Get the shadow
synopsis: get the shadow for an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.get.shadow.writer.main
services:
iot-data-plane: {GetThingShadow}
iot-data-plane_UpdateThingShadow:
title: Update the shadow for the specified thing using an &AWS; SDK
title_abbrev: Update the shadow
synopsis: update the shadow for an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.update.shadow.thing.main
services:
iot-data-plane: {UpdateThingShadow}
218 changes: 218 additions & 0 deletions .doc_gen/metadata/iot_metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
# zexi 0.4.0
iot_Hello:
title: Hello &IoT;
title_abbrev: Hello &IoT;
synopsis: get started using &IoT;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
sdkguide:
excerpts:
- description:
snippet_tags:
- iot.java2.hello_iot.main
services:
iot: {listThings}
iot_DescribeEndpoint:
title: Get information about an endpoint using an &AWS; SDK
title_abbrev: Get endpoint information
synopsis: get &IoT; endpoint information.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.describe.endpoint.main
Rust:
versions:
- sdk_version: 1
Expand All @@ -31,3 +56,196 @@ iot_ListThings:
- iot.rust.list-things
services:
iot: {ListThings}
iot_ListCertificates:
title: List your &IoT; certificates using an &AWS; SDK
title_abbrev: List your certificates
synopsis: list your &IoT; certificates.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.list.certs.main
services:
iot: {ListCertificates}
iot_CreateCertificate:
title: Create an &IoT; certificate using an &AWS; SDK
title_abbrev: Create a certificate
synopsis: create an &IoT; certificate.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.create.cert.main
services:
iot: {CreateKeysAndCertificate}
iot_DeleteCertificate:
title: Delete an &IoT; certificate using an &AWS; SDK
title_abbrev: Delete a certificate
synopsis: delete an &IoT; certificate.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.delete.cert.main
services:
iot: {DeleteCertificate}
iot_SearchIndex:
title: Query the &IoT; search index using an &AWS; SDK
title_abbrev: Query the search index
synopsis: query the &IoT; search index.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.search.thing.main
services:
iot: {SearchIndex}
iot_DeleteThing:
title: Delete an &IoT; thing using an &AWS; SDK
title_abbrev: Delete a thing
synopsis: delete an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.delete.thing.main
services:
iot: {DeleteThing}
iot_DescribeThing:
title: Describe an &IoT; thing using an &AWS; SDK
title_abbrev: Describe a thing
synopsis: describe an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.describe.thing.main
services:
iot: {DescribeThing}
iot_AttachThingPrincipal:
title: Attach a certificate to an &IoT; thing using an &AWS; SDK
title_abbrev: Attach a certificate
synopsis: attach an &IoT; certificate.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.attach.thing.main
services:
iot: {AttachThingPrincipal}
iot_DetachThingPrincipal:
title: Detach a certificate from an &IoT; thing using an &AWS; SDK
title_abbrev: Detach a certificate
synopsis: detach an &IoT; certificate.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.detach.thing.main
services:
iot: {DetachThingPrincipal}
iot_UpdateThing:
title: Update an &IoT; thing using an &AWS; SDK
title_abbrev: Update a thing
synopsis: update an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.update.thing.main
services:
iot: {UpdateThing}
iot_CreateRule:
title: Create an &IoT; rule using an &AWS; SDK
title_abbrev: Create a rule
synopsis: create an &IoT; rule.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.create.rule.main
services:
iot: {CreateTopicRule}
iot_CreateThing:
title: Create &IoT; things using an &AWS; SDK
title_abbrev: Create a thing
synopsis: create an &IoT; thing.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
excerpts:
- description:
snippet_tags:
- iot.java2.create.thing.main
services:
iot: {CreateThing}
iot_Scenario:
title: Working with &IoT; devices, things, and shadows using &IoT; SDK
title_abbrev: Working with device management use cases
synopsis: working with &IoT; device management use cases using &IoT; SDK
category: Scenarios
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iot
sdkguide:
excerpts:
- description:
snippet_tags:
- iot.java2.scenario.main
services:
iot: {}
82 changes: 82 additions & 0 deletions javav2/example_code/iot/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# AWS IoT Core code examples for the SDK for Java

## Overview
This README discusses how to run and test the AWS SDK for Java (V2) examples for AWS IoT Core.

AWS IoT Core enables secure two-way communication between internet-connected devices and AWS services with device gateway and device SDK capabilities.

## ⚠️ Important
* The SDK for Java examples perform AWS operations for the account and AWS Region for which you've specified credentials. Running these examples might incur charges on your account. For details about the charges you can expect for a given service and API operation, see [AWS Pricing](https://aws.amazon.com/pricing/).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

## Code examples

The credential provider used in all code examples is the default credential provider. For more information, see [Using credentials](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html).

### Get started

- [Hello AWS IoT Core](src/main/java/com/example/iot/HelloIoT.java) (`ListThings`)


### Single action

The following examples use the **IotClient** object:

- [Attach a certificate to an AWS IoT thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`AttachThingPrincipal`)
- [Create an AWS IoT thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`CreateThing`)
- [Create an AWS IoT certificate](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`CreateKeysAndCertificate`)
- [Create an AWS IoT rule](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`CreateTopicRule`)
- [Delete an AWS IoT certificate](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`DeleteCertificate`)
- [Delete an AWS IoT thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`DeleteThing`)
- [Detach a certificate from an AWS IoT thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`DetachThingPrincipal`)
- [Get information about an endpoint](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`DescribeEndpoint`)
- [List your AWS IoT certificates](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`ListCertificates`)
- [Query the AWS IoT search index.](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`SearchIndex`)
- [Update an AWS IoT thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`UpdateThing`)

The following examples use the **IotDataPlaneClient** object:

- [Get the shadow for the specified thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`GetThingShadow`)
- [Update the shadow for the specified thing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/iot/src/main/java/com/example/iot/IotScenario.java) (`UpdateThingShadow`)

### Scenarios

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

* [Perform device management use cases ](src/main/java/com/example/iot/IotScenario.java)

## Running the AWS IoT Java files

Some of these examples perform *destructive* operations on AWS resources, such as deleting an AWS IoT Thing. **Be very careful** when running an operation that deletes or modifies AWS resources in your account. We recommend creating separate test-only resources when experimenting with these examples.

To run these examples, set up your development environment. For more information,
see [Get started with the SDK for Java](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html).


## Testing the AWS IoT Java files

You can test the Java code examples for AWS IoT by running a test file named **IoTTests**. This file uses JUnit 5 to run the JUnit tests and is located in the **src/test/java** folder. For more information, see [https://junit.org/junit5/](https://junit.org/junit5/).

You can run the JUnit tests from an IDE, such as IntelliJ, or from the command line. As each test runs, you can view messages that inform you if the various tests succeed or fail. For example, the following message informs you that the Test passed.

Test 2 passed

**WARNING**: _Running these JUnit tests manipulates real Amazon resources and might incur charges on your account._

### Properties file
Before running the JUnit tests, you must define values in the **config.properties** file located in the **resources** folder. This file contains values that are required to run the JUnit tests. For example, you define a tableId used in the tests. If you do not define all values, the JUnit tests fail.

Define these values to successfully run the JUnit tests:

- **roleARN** - The ARN of an IAM role that has permission to work with AWS IOT.
- **snsAction** - An ARN of an SNS topic.

## Additional resources
* [Developer Guide - AWS SDK for Java](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html).
* [Developer Guide - AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/iot-gs.html).
* [Interface IotClient](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/iot/IotClient.html).

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0
24 changes: 24 additions & 0 deletions javav2/example_code/iot/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>

<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.2//EN"
"https://checkstyle.org/dtds/configuration_1_2.dtd">

<module name="Checker">
<module name="TreeWalker">

<module name="IllegalCatch"/>
<module name="EmptyStatement"/>
<module name="AvoidStarImport"/>
<module name="UnusedImports"/>
<module name="ParameterAssignment"/>
<module name="LocalVariableName"/>
<module name="NoLineWrap"/>
<module name="SingleSpaceSeparator"/>
<module name="MethodName"/>
<module name="MemberName"/>
<module name="LocalVariableName"/>
<module name="LeftCurly"/>
<module name="RightCurly"/>
</module>
</module>
Loading

0 comments on commit b532be1

Please sign in to comment.