Use ListAssetModels with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListAssetModels with an AWS SDK or CLI

The following code examples show how to use ListAssetModels.

CLI
AWS CLI

To list all asset models

The following list-asset-models example lists all asset models that are defined in your AWS account in the current Region.

aws iotsitewise list-asset-models

Output:

{ "assetModelSummaries": [ { "id": "a1b2c3d4-5678-90ab-cdef-22222EXAMPLE", "arn": "arn:aws:iotsitewise:us-west-2:123456789012:asset-model/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE", "name": "Wind Farm Model", "description": "Represents a wind farm that comprises many wind turbines", "creationDate": 1575671284.0, "lastUpdateDate": 1575671988.0, "status": { "state": "ACTIVE" } }, { "id": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "arn": "arn:aws:iotsitewise:us-west-2:123456789012:asset-model/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "name": "Wind Turbine Model", "description": "Represents a wind turbine manufactured by Example Corp", "creationDate": 1575671207.0, "lastUpdateDate": 1575686273.0, "status": { "state": "ACTIVE" } } ] }

For more information, see Listing all asset models in the AWS IoT SiteWise User Guide.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Retrieves the asset model ID for the given asset model name. * * @param assetModelName the name of the asset model for the ID. * @return a {@link CompletableFuture} that represents a {@link String} result of the asset model ID or null if the * asset model cannot be found. The calling code can attach callbacks, then handle the result or exception * by calling {@link CompletableFuture#join()} or {@link CompletableFuture#get()}. * <p> * If any completion stage in this method throws an exception, the method logs the exception cause and keeps * it available to the calling code as a {@link CompletionException}. By calling * {@link CompletionException#getCause()}, the calling code can access the original exception. */ public CompletableFuture<String> getAssetModelIdAsync(String assetModelName) { ListAssetModelsRequest listAssetModelsRequest = ListAssetModelsRequest.builder().build(); return getAsyncClient().listAssetModels(listAssetModelsRequest) .handle((listAssetModelsResponse, exception) -> { if (exception != null) { logger.error("Failed to retrieve Asset Model ID: {}", exception.getCause().getMessage()); throw (CompletionException) exception; } for (AssetModelSummary assetModelSummary : listAssetModelsResponse.assetModelSummaries()) { if (assetModelSummary.name().equals(assetModelName)) { return assetModelSummary.id(); } } return null; }); }
  • For API details, see ListAssetModels in AWS SDK for Java 2.x API Reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class IoTSitewiseWrapper: """Encapsulates AWS IoT SiteWise actions using the client interface.""" def __init__(self, iotsitewise_client: client) -> None: """ Initializes the IoTSitewiseWrapper with an AWS IoT SiteWise client. :param iotsitewise_client: A Boto3 AWS IoT SiteWise client. This client provides low-level access to AWS IoT SiteWise services. """ self.iotsitewise_client = iotsitewise_client self.entry_id = 0 # Incremented to generate unique entry IDs for batch_put_asset_property_value. @classmethod def from_client(cls) -> "IoTSitewiseWrapper": """ Creates an IoTSitewiseWrapper instance with a default AWS IoT SiteWise client. :return: An instance of IoTSitewiseWrapper initialized with the default AWS IoT SiteWise client. """ iotsitewise_client = boto3.client("iotsitewise") return cls(iotsitewise_client) def list_asset_models(self) -> List[Dict[str, Any]]: """ Lists all AWS IoT SiteWise Asset Models. :return: A list of dictionaries containing information about each asset model. """ try: asset_models = [] paginator = self.iotsitewise_client.get_paginator("list_asset_models") pages = paginator.paginate() for page in pages: asset_models.extend(page["assetModelSummaries"]) return asset_models except ClientError as err: logger.error( "Error listing asset models. Here's why %s", err.response["Error"]["Message"], ) raise
  • For API details, see ListAssetModels in AWS SDK for Python (Boto3) API Reference.