Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Dapatkan semua perjanjian IDs menggunakan AWS SDK
Contoh kode berikut menunjukkan cara mendapatkan semua kesepakatanIDs.
- Java
-
- SDKuntuk Java 2.x
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di repositori Perpustakaan Kode AWS Marketplace API Referensi
. // 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 GetAllAgreementsIds { /* * Get all purchase agreements ids 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<String> agreementIds = getAllAgreementIds(); ReferenceCodesUtils.formatOutput(agreementIds); } public static List<String> getAllAgreementIds() { 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()); } List<String> agreementIds = new ArrayList<String>(); for (AgreementViewSummary summary : agreementSummaryList) { agreementIds.add(summary.agreementId()); } return agreementIds; } }
-
Untuk API detailnya, lihat SearchAgreementsdi AWS SDK for Java 2.x APIReferensi.
-
- Python
-
- SDKuntuk Python (Boto3)
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di repositori Perpustakaan Kode AWS Marketplace API Referensi
. # 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 agreement ids AG-09 """ import logging import boto3 from botocore.exceptions import ClientError mp_client = boto3.client("marketplace-agreement") logger = logging.getLogger(__name__) MAX_PAGE_RESULTS = 10 def get_agreements(): AgreementSummaryList = [] agreement_id_list = [] try: agreements = mp_client.search_agreements( catalog="AWSMarketplace", maxResults=MAX_PAGE_RESULTS, filters=[ {"name": "PartyType", "values": ["Proposer"]}, {"name": "AgreementType", "values": ["PurchaseAgreement"]}, ], ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise AgreementSummaryList.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=[ {"name": "PartyType", "values": ["Proposer"]}, {"name": "AgreementType", "values": ["PurchaseAgreement"]}, ], ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise AgreementSummaryList.extend(agreements["agreementViewSummaries"]) for agreement in AgreementSummaryList: agreement_id_list.append(agreement["agreementId"]) return agreement_id_list if __name__ == "__main__": agreement_id_list = get_agreements() print(agreement_id_list)
-
Untuk API detailnya, lihat SearchAgreements AWSSDKReferensi Python (Boto3). API
-