AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用获取所有协议 AWS SDK
以下代码示例展示了如何获取所有协议。
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整的示例,学习如何在AWS Marketplace API参考代码库存储库
中设置和运行。 // 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAllAgreements { /* * Get all purchase agreements with party type = proposer; * Depend on the number of agreements in your account, this code may take some time to finish. */ public static void main(String[] args) { List<AgreementViewSummary> agreementSummaryList = getAllAgreements(); ReferenceCodesUtils.formatOutput(agreementSummaryList); } public static List<AgreementViewSummary> getAllAgreements() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // get all filters Filter partyType = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementType = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); List<Filter> searchFilters = new ArrayList<Filter>(); searchFilters.addAll(Arrays.asList(partyType, agreementType)); // Save all results in a list array List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(searchFilters) .build(); SearchAgreementsResponse searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); while (searchAgreementsResponse.nextToken() != null && searchAgreementsResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .nextToken(searchAgreementsResponse.nextToken()) .filters(searchFilters).build(); searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); } return agreementSummaryList; } }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 SearchAgreements” 中的。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整的示例,学习如何在AWS Marketplace API参考代码库存储库
中设置和运行。 # 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 all agreements AG-01 """ import logging import boto3 import utils.helpers as helper from botocore.exceptions import ClientError mp_client = boto3.client("marketplace-agreement") logger = logging.getLogger(__name__) MAX_PAGE_RESULTS = 10 party_type_list = ["Proposer"] agreement_type_list = ["PurchaseAgreement"] filter_list = [ {"name": "PartyType", "values": party_type_list}, {"name": "AgreementType", "values": agreement_type_list}, ] agreement_results_list = [] def get_agreements(filter_list=filter_list): try: agreements = mp_client.search_agreements( catalog="AWSMarketplace", maxResults=MAX_PAGE_RESULTS, filters=filter_list, ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise e agreement_results_list.extend(agreements["agreementViewSummaries"]) while "nextToken" in agreements and agreements["nextToken"] is not None: try: agreements = mp_client.search_agreements( catalog="AWSMarketplace", maxResults=MAX_PAGE_RESULTS, nextToken=agreements["nextToken"], filters=filter_list, ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise e agreement_results_list.extend(agreements["agreementViewSummaries"]) return agreement_results_list if __name__ == "__main__": agreements_list = get_agreements(filter_list) helper.pretty_print_datetime(agreements_list)
-
有关API详细信息,请参阅SearchAgreements中的 AWS SDKPython (Boto3) API 参考。
-
获得所有同意 IDs
从协议中获取客户 ID