There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.
Code examples for AWS IoT FleetWise using AWS SDKs
The following code examples show you how to use AWS IoT FleetWise with an AWS software development kit (SDK).
Basics are code examples that show you how to perform the essential operations within a service.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Get started
The following code examples show how to get started using AWS IoT FleetWise.
- Java
-
- SDK for Java 2.x
-
public class HelloFleetwise {
public static void main(String[] args) {
ListSignalCatalogs();
}
public static void ListSignalCatalogs() {
try (IoTFleetWiseClient fleetWiseClient = IoTFleetWiseClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(DefaultCredentialsProvider.create())
.build()) {
ListSignalCatalogsRequest request = ListSignalCatalogsRequest.builder()
.maxResults(10) // Optional: limit per page
.build();
ListSignalCatalogsIterable paginator = fleetWiseClient.listSignalCatalogsPaginator(request);
boolean found = false;
for (ListSignalCatalogsResponse response : paginator) {
for (SignalCatalogSummary summary : response.summaries()) {
found = true;
System.out.println("Catalog Name: " + summary.name());
System.out.println("ARN: " + summary.arn());
System.out.println("Created: " + summary.creationTime());
System.out.println("Last Modified: " + summary.lastModificationTime());
System.out.println("---------------");
}
}
if (!found) {
System.out.println("No AWS Fleetwise Signal Catalogs were found.");
}
} catch (IoTFleetWiseException e) {
System.err.println("Error listing signal catalogs: " + e.awsErrorDetails().errorMessage());
throw new RuntimeException(e);
}
}
}
- Kotlin
-
- SDK for Kotlin
-
/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main() {
listSignalCatalogs()
}
/**
* Lists the AWS FleetWise Signal Catalogs associated with the current AWS account.
*/
suspend fun listSignalCatalogs() {
val request = ListSignalCatalogsRequest {
maxResults = 10
}
IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient ->
val response = fleetwiseClient.listSignalCatalogs(request)
val summaries = response.summaries
if (summaries.isNullOrEmpty()) {
println("No AWS FleetWise Signal Catalogs were found.")
} else {
summaries.forEach { summary ->
with(summary) {
println("Catalog Name: $name")
println("ARN: $arn")
println("Created: $creationTime")
println("Last Modified: $lastModificationTime")
println("---------------")
}
}
}
}
}