Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Descreva todas as entidades em uma única chamada usando um AWS SDK
Os exemplos de código a seguir mostram como descrever todas as entidades em uma única chamada.
- Java
-
- SDKpara Java 2.x
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de Códigos de AWS Marketplace API Referência
. // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package com.example.awsmarketplace.catalogapi; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient; import software.amazon.awssdk.services.marketplacecatalog.model.BatchDescribeEntitiesRequest; import software.amazon.awssdk.services.marketplacecatalog.model.EntityRequest; import software.amazon.awssdk.services.marketplacecatalog.model.BatchDescribeEntitiesResponse; import software.amazon.awssdk.services.marketplacecatalog.model.EntityDetail; import software.amazon.awssdk.services.marketplacecatalog.model.BatchDescribeErrorDetail; import java.util.Arrays; import java.util.Map; public class BatchDescribeEntities { /* * BatchDescribe my entities in a single call and * check if it contains all the information I need to know about the entities. */ public static void main(String[] args) { MarketplaceCatalogClient marketplaceCatalogClient = MarketplaceCatalogClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); BatchDescribeEntitiesRequest batchDescribeEntitiesRequest = BatchDescribeEntitiesRequest.builder() .entityRequestList(Arrays.asList( EntityRequest.builder() .catalog(AWS_MP_CATALOG).entityId(OFFER_ID) .build(), EntityRequest.builder() .catalog(AWS_MP_CATALOG).entityId(PRODUCT_ID) .build())) .build(); BatchDescribeEntitiesResponse batchDescribeEntitiesResponse = marketplaceCatalogClient.batchDescribeEntities(batchDescribeEntitiesRequest); // Reading the successful entities response Map<String, EntityDetail> entityDetailsMap = batchDescribeEntitiesResponse.entityDetails(); for (Map.Entry<String, EntityDetail> entry : entityDetailsMap.entrySet()) { System.out.println("EntityId: " + entry.getKey()); ReferenceCodesUtils.formatOutput(entry.getValue()); } // Logging the failed entities error details Map<String, BatchDescribeErrorDetail> entityErrorsMap = batchDescribeEntitiesResponse.errors(); for (Map.Entry<String, BatchDescribeErrorDetail> entry : entityErrorsMap.entrySet()) { System.out.println(String.format("EntityId: %s, ErrorCode: %s, ErrorMessage: %s", entry.getKey(), entry.getValue().errorCode(), entry.getValue().errorMessage())); } } }
-
Para API obter detalhes, consulte BatchDescribeEntitiesem AWS SDK for Java 2.x APIReferência.
-
- Python
-
- SDKpara Python (Boto3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de Códigos de AWS Marketplace API Referência
. """ Purpose Shows how to use the AWS SDK for Python (Boto3) to describe for multiple entities information in the AWS Marketplace Catalog CAPI-98 """ import json import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) PRODUCT_ID = "prod-1111111111111" OFFER_ID = "offer-1111111111111" MARKETPLACE_CATALOG = "AWSMarketplace" def pretty_print(response): json_object = json.dumps(response, indent=4) print(json_object) def get_entities_information(mp_client): """ Returns information about a given product Args: entity_id str: Entity to return Returns: dict: Dictionary of product information """ entity_request_list_param = [ {'EntityId': PRODUCT_ID, 'Catalog': MARKETPLACE_CATALOG}, {'EntityId': OFFER_ID, 'Catalog': MARKETPLACE_CATALOG} ] try: response = mp_client.batch_describe_entities( EntityRequestList=entity_request_list_param ) return response except ClientError as e: logger.exception("Unexpected error: %s", e) raise def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Looking for entities in the AWS Marketplace Catalog.") print("-" * 88) mp_client = boto3.client("marketplace-catalog") response = get_entities_information(mp_client) print("Successful entities response -") pretty_print(response["EntityDetails"]) print("Failed entities response -") pretty_print(response["Errors"]) if __name__ == "__main__": usage_demo()
-
Para API obter detalhes, consulte a BatchDescribeEntitiesReferência AWS SDK do Python (Boto3). API
-