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 as instâncias de cada dimensão comprada em um contrato usando um AWS SDK
Os exemplos de código a seguir mostram como obter as instâncias de cada dimensão compradas em 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.AcceptedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsDimensionInstances { /* * get instances of each dimension that buyer has purchased in the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; Map<String, List<Dimension>> dimensionMap = getDimensions(agreementId); ReferenceCodesUtils.formatOutput(dimensionMap); } public static Map<String, List<Dimension>> getDimensions(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); GetAgreementTermsRequest getAgreementTermsRequest = GetAgreementTermsRequest.builder().agreementId(agreementId) .build(); GetAgreementTermsResponse getAgreementTermsResponse = marketplaceAgreementClient.getAgreementTerms(getAgreementTermsRequest); Map<String, List<Dimension>> dimensionMap = new HashMap<String, List<Dimension>>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { List<Dimension> dimensionsList = new ArrayList<Dimension>(); if (acceptedTerm.configurableUpfrontPricingTerm() != null) { String selectorValue = ""; if (acceptedTerm.configurableUpfrontPricingTerm().configuration() != null) { if (acceptedTerm.configurableUpfrontPricingTerm().configuration().selectorValue() != null) { selectorValue = acceptedTerm.configurableUpfrontPricingTerm().configuration().selectorValue(); } if (acceptedTerm.configurableUpfrontPricingTerm().configuration().hasDimensions()) { dimensionsList = acceptedTerm.configurableUpfrontPricingTerm().configuration().dimensions(); } } if (selectorValue.length() > 0) { dimensionMap.put(selectorValue, dimensionsList); } } } return dimensionMap; } }-
Para obter detalhes da API, consulte GetAgreementTermsa 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 instances of each dimension that buyer has purchased in the agreement AG-30 """ import logging import boto3 import utils.helpers as helper from botocore.exceptions import ClientError logger = logging.getLogger(__name__) # agreement id AGREEMENT_ID = "agmt-1111111111111111111111111" # attribute name ROOT_ELEM = "acceptedTerms" TERM_NAME = "configurableUpfrontPricingTerm" CONFIG_ELEM = "configuration" ATTRIBUTE_NAME = "selectorValue" logger = logging.getLogger(__name__) def get_agreement_information(mp_client, entity_id): """ Returns customer AWS Account id about a given agreement Args: entity_id str: Entity to return Returns: dict: Dictionary of agreement information """ try: terms = mp_client.get_agreement_terms(agreementId=entity_id) dimensionKeyValueMap = {} for term in terms[ROOT_ELEM]: if TERM_NAME in term: if CONFIG_ELEM in term[TERM_NAME]: confParam = term[TERM_NAME][CONFIG_ELEM] if ATTRIBUTE_NAME in confParam: selectValue = confParam["selectorValue"] dimensionKeyValueMap["selectorValue"] = selectValue if "dimensions" in confParam: dimensionKeyValueMap["dimensions"] = confParam["dimensions"] """ for dimension in confParam['dimensions']: if 'dimensionKey' in dimension: dimensionValue = dimension['dimensionValue'] dimensionKey = dimension['dimensionKey'] print(f"Selector: {selectValue}, Dimension Key: {dimensionKey}, Dimension Value: {dimensionValue}") dimensionKeyValueMap[dimensionKey] = dimensionValue """ return dimensionKeyValueMap 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 an agreement in the AWS Marketplace.") print("-" * 88) mp_client = boto3.client("marketplace-agreement") helper.pretty_print_datetime(get_agreement_information(mp_client, AGREEMENT_ID)) if __name__ == "__main__": usage_demo()-
Para obter detalhes da API, consulte a GetAgreementTermsReferência da API AWS SDK for Python (Boto3).
-