D'autres AWS SDK exemples sont disponibles dans le GitHub dépôt AWS Doc SDK Examples
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Obtenez les détails d'un produit et d'une offre dans le cadre d'un contrat à l'aide d'un AWS SDK
Les exemples de code suivants montrent comment obtenir les détails d'un produit et d'une offre dans le cadre d'un accord.
- Java
-
- SDKpour Java 2.x
-
Note
Il y en a plus à ce sujet GitHub. Consultez l'exemple complet et apprenez à le configurer et à l'exécuter dans le référentiel de la bibliothèque de codes de AWS Marketplace API référence
. // 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; } }
-
Pour API plus de détails, voir DescribeAgreementla section AWS SDK for Java 2.x APIRéférence.
-
- Python
-
- SDKpour Python (Boto3)
-
Note
Il y en a plus à ce sujet GitHub. Consultez l'exemple complet et apprenez à le configurer et à l'exécuter dans le référentiel de la bibliothèque de codes de AWS Marketplace API référence
. # 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)
-
Pour API plus de détails, reportez-vous DescribeAgreementà la section AWS SDKpour la référence Python (Boto3). API
-