Obtenha detalhes do produto e da oferta de um contrato usando um AWS SDK - AWS SDKExemplos de código

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á.

Obtenha detalhes do produto e da oferta de um contrato usando um AWS SDK

Os exemplos de código a seguir mostram como obter detalhes do produto e da oferta de um contrato.

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.agreementapi; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient; import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementRequest; import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Resource; import java.util.ArrayList; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityRequest; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityResponse; public class GetProductAndOfferDetailFromAgreement { public static void main(String[] args) { // call Agreement API to get offer and product information for the agreement String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<DescribeEntityResponse> entityResponseList = getEntities(agreementId); for (DescribeEntityResponse response : entityResponseList) { ReferenceCodesUtils.formatOutput(response); } } public static List<DescribeEntityResponse> getEntities(String agreementId) { List<DescribeEntityResponse> entityResponseList = new ArrayList<DescribeEntityResponse> (); MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeAgreementRequest describeAgreementRequest = DescribeAgreementRequest.builder() .agreementId(agreementId) .build(); DescribeAgreementResponse describeAgreementResponse = marketplaceAgreementClient.describeAgreement(describeAgreementRequest); // get offer id for the given agreement String offerId = describeAgreementResponse.proposalSummary().offerId(); // get all the product ids for this agreement List<String> productIds = new ArrayList<String>(); for (Resource resource : describeAgreementResponse.proposalSummary().resources()) { productIds.add(resource.id()); } // call Catalog API to get the details of the offer and products MarketplaceCatalogClient marketplaceCatalogClient = MarketplaceCatalogClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeEntityRequest describeEntityRequest = DescribeEntityRequest.builder() .catalog(AWS_MP_CATALOG) .entityId(offerId).build(); DescribeEntityResponse describeEntityResponse = marketplaceCatalogClient.describeEntity(describeEntityRequest); entityResponseList.add(describeEntityResponse); for (String productId : productIds) { describeEntityRequest = DescribeEntityRequest.builder() .catalog(AWS_MP_CATALOG) .entityId(productId).build(); describeEntityResponse = marketplaceCatalogClient.describeEntity(describeEntityRequest); System.out.println("Print details for product " + productId); entityResponseList.add(describeEntityResponse); } return entityResponseList; } }
  • Para API obter detalhes, consulte DescribeAgreementem 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.

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to use the AWS SDK for Python (Boto3) to get product and offer details in a given agreement AG-10 """ import argparse import logging import boto3 import utils.helpers as helper from botocore.exceptions import ClientError mpa_client = boto3.client("marketplace-agreement") mpc_client = boto3.client("marketplace-catalog") logger = logging.getLogger(__name__) def get_agreement_information(agreement_id): """ Returns information about a given agreement Args: agreement_id str: Entity to return Returns: dict: Dictionary of agreement information """ try: agreement = mpa_client.describe_agreement(agreementId=agreement_id) return agreement except ClientError as e: if e.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Agreement with ID %s not found.", agreement_id) else: logger.error("Unexpected error: %s", e) def get_entity_information(entity_id): """ Returns information about a given entity Args: entity_id str: Entity to return Returns: dict: Dictionary of entity information """ try: response = mpc_client.describe_entity( Catalog="AWSMarketplace", EntityId=entity_id, ) return response except ClientError as e: if e.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Entity with ID %s not found.", entity_id) else: logger.error("Unexpected error: %s", e) def get_agreement_components(agreement_id): agreement_component_list = [] agreement = get_agreement_information(agreement_id) if agreement is not None: productIds = [] for resource in agreement["proposalSummary"]["resources"]: productIds.append(resource["id"]) for product_id in productIds: product_document = get_entity_information(product_id) product_document_dict = {} product_document_dict["product_id"] = product_id product_document_dict["document"] = product_document agreement_component_list.append(product_document_dict) offerId = agreement["proposalSummary"]["offerId"] offer_document = get_entity_information(offerId) offer_document_dict = {} offer_document_dict["offer_id"] = offerId offer_document_dict["document"] = offer_document agreement_component_list.append(offer_document_dict) return agreement_component_list else: print("Agreement with ID " + args.agreement_id + " is not found") if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") parser = argparse.ArgumentParser() parser.add_argument( "--agreement_id", "-aid", help="Provide agreement ID to search for product and offer detail", required=True, ) args = parser.parse_args() product_offer_detail = get_agreement_components(agreement_id=args.agreement_id) helper.pretty_print_datetime(product_offer_detail)
  • Para API obter detalhes, consulte a DescribeAgreementReferência AWS SDK do Python (Boto3). API