Há mais exemplos de AWS SDK disponíveis no 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 o tipo de produto de um contrato usando um AWS SDK
Os exemplos de código a seguir mostram como obter o tipo de produto de um contrato.
- Java
-
- SDK para Java 2.x
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da AWS Marketplace API Reference Code Library
. // 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 static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import java.util.ArrayList; import java.util.List; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementProductType { /* * Obtain the Product Type of the product the agreement was created on */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<String> productIds = getProducts(agreementId); ReferenceCodesUtils.formatOutput(productIds); } public static List<String> getProducts(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeAgreementRequest describeAgreementRequest = DescribeAgreementRequest.builder() .agreementId(agreementId) .build(); DescribeAgreementResponse describeAgreementResponse = marketplaceAgreementClient.describeAgreement(describeAgreementRequest); List<String> productIds = new ArrayList<String>(); for (Resource resource : describeAgreementResponse.proposalSummary().resources()) { productIds.add(resource.id() + ":" + resource.type()); } return productIds; } }-
Para obter detalhes da API, consulte DescribeAgreementa Referência AWS SDK for Java 2.x da API.
-
- Python
-
- SDK para Python (Boto3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da AWS Marketplace API Reference Code Library
. # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Obtain the Product Type of the product the agreement was created on AG-11 """ import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) # agreement id AGREEMENT_ID = "agmt-1111111111111111111111111" def get_agreement_information(mp_client, entity_id): """ Returns information about a given agreement Args: entity_id str: Entity to return Returns: dict: Dictionary of agreement information """ try: agreement = mp_client.describe_agreement(agreementId=entity_id) return agreement except ClientError as e: if e.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Agreement with ID %s not found.", entity_id) else: logger.error("Unexpected error: %s", e) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Looking for offer and product details in a given agreement by agreement id.") print("-" * 88) mp_client = boto3.client("marketplace-agreement") agreement = get_agreement_information(mp_client, AGREEMENT_ID) if agreement is not None: productHash = {} for resource in agreement["resourceSummaries"]: productHash[resource["resourceId"]] = resource["resourceType"] for key, value in productHash.items(): print(f"Product ID: {key} | Product Type: {value}") else: print("Agreement with ID " + AGREEMENT_ID + " is not found") if __name__ == "__main__": usage_demo()-
Para obter detalhes da API, consulte a DescribeAgreementReferência da API AWS SDK for Python (Boto3).
-