Skip to content

Instantly share code, notes, and snippets.

@steveperkins
Last active September 8, 2016 01:56
Show Gist options
  • Save steveperkins/f3e775ce6fead2e5a00657a4002ec217 to your computer and use it in GitHub Desktop.
Save steveperkins/f3e775ce6fead2e5a00657a4002ec217 to your computer and use it in GitHub Desktop.
// Build an authenticated client object
// This pattern repeats from https://www.linkedin.com/pulse/sending-sms-from-java-aws-sns-steve-perkins
AWSIot iotClient = AWSIotClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(CLIENT_TOKEN, CLIENT_SECRET)))
.withRegion(Regions.US_WEST_2)
.build();
// Send the ListThingsRequest to AWS IoT synchronously
ListThingsResult result = iotClient.listThings(new ListThingsRequest());
List<ThingAttribute> things = result.getThings();
// Now you have access to the Thing's name, thing type, version, and a map of attributes/tags
// Get all things of a specific type
String typeName = "LightsideSensor";
ListThingsRequest listThingsRequest = new ListThingsRequest()
.withThingTypeName(typeName)
.withMaxResults(200);
ListThingsResult result = AwsClientFactory.getIotClient().listThings(listThingsRequest);
List<ThingAttribute> things = result.getThings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment