View a markdown version of this page

Crie um novo contrato de teste gratuito da AMI usando um AWS SDK - AWS Exemplos de código SDK

Há mais exemplos de AWS SDK disponíveis no repositório AWS Doc SDK Examples GitHub .

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á.

Crie um novo contrato de teste gratuito da AMI usando um AWS SDK

Os exemplos de código a seguir mostram como criar um novo contrato de teste gratuito da AMI.

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 Biblioteca de códigos da referência de API do AWS Marketplace.

package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to create an AMI Free Trial agreement * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to an AMI product that offers a free trial period. * The free trial includes a FreeTrialPricingTerm alongside a UsageBasedPricingTerm. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * </ul> */ public class NewAmiFreeTrial { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in your offer. private static final String FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the UsageBasedPricingTerm in your offer (applies after the trial ends). private static final String USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the SupportTerm in your offer. private static final String SUPPORT_TERM_ID = "<your-support-term-id>"; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; public static void main(String[] args) { createAndAcceptAmiFreeTrialAgreementRequest(); } /** * Creates an AMI Free Trial agreement. * The FreeTrialPricingTerm grants access at no cost for the trial period. * The UsageBasedPricingTerm defines the charges that apply once the trial ends. */ private static void createAndAcceptAmiFreeTrialAgreementRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm freeTrialPricingTerm = RequestedTerm.builder() .id(FREE_TRIAL_PRICING_TERM_ID) .build(); RequestedTerm usageBasedPricingTerm = RequestedTerm.builder() .id(USAGE_BASED_PRICING_TERM_ID) .build(); RequestedTerm supportTerm = RequestedTerm.builder() .id(SUPPORT_TERM_ID) .build(); RequestedTerm legalTerm = RequestedTerm.builder() .id(LEGAL_TERM_ID) .build(); CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(freeTrialPricingTerm, usageBasedPricingTerm, supportTerm, legalTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); } }
JavaScript
SDK para JavaScript (v3)
nota

Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace.

const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to create an AMI Free Trial agreement * using the AWS Marketplace Agreement Service APIs. * * Scenario: A buyer subscribes to an AMI product that offers a free trial period. * The free trial includes a FreeTrialPricingTerm alongside a UsageBasedPricingTerm. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in your offer. const FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the UsageBasedPricingTerm in your offer (applies after the trial ends). const USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the SupportTerm in your offer. const SUPPORT_TERM_ID = "<your-support-term-id>"; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; /** * Creates an AMI Free Trial agreement. * The FreeTrialPricingTerm grants access at no cost for the trial period. * The UsageBasedPricingTerm defines the charges that apply once the trial ends. */ async function createAndAcceptAmiFreeTrialAgreementRequest() { const client = new MarketplaceAgreementClient(); const freeTrialPricingTerm = { id: FREE_TRIAL_PRICING_TERM_ID }; const usageBasedPricingTerm = { id: USAGE_BASED_PRICING_TERM_ID }; const supportTerm = { id: SUPPORT_TERM_ID }; const legalTerm = { id: LEGAL_TERM_ID }; const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [freeTrialPricingTerm, usageBasedPricingTerm, supportTerm, legalTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); } createAndAcceptAmiFreeTrialAgreementRequest();
Python
SDK para Python (Boto3)
nota

Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace.

""" Demonstrates how to create an AMI Free Trial agreement using the AWS Marketplace Agreement Service APIs. Scenario: A buyer subscribes to an AMI product that offers a free trial period. The free trial includes a FreeTrialPricingTerm alongside a UsageBasedPricingTerm. Before running this sample, replace the placeholder constants below with values from your AWS Marketplace offer: - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. - Term IDs (starting with term-) — found in the offer's term list. """ import boto3 from utils.agreement_api_utils import generate_client_token class NewAmiFreeTrial: # The agreementProposalId from the offer. AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>" # Term ID for the FreeTrialPricingTerm in your offer. FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>" # Term ID for the UsageBasedPricingTerm in your offer (applies after the trial ends). USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>" # Term ID for the SupportTerm in your offer. SUPPORT_TERM_ID = "<your-support-term-id>" # Term ID for the LegalTerm in your offer. LEGAL_TERM_ID = "<your-legal-term-id>" @staticmethod def create_and_accept_ami_free_trial_agreement_request(): """ Create an AMI Free Trial agreement. The FreeTrialPricingTerm grants access at no cost for the trial period. The UsageBasedPricingTerm defines the charges that apply once the trial ends. """ client = boto3.client("marketplace-agreement") create_response = client.create_agreement_request( clientToken=generate_client_token(), intent="NEW", requestedTerms=[ {"id": NewAmiFreeTrial.FREE_TRIAL_PRICING_TERM_ID}, {"id": NewAmiFreeTrial.USAGE_BASED_PRICING_TERM_ID}, {"id": NewAmiFreeTrial.SUPPORT_TERM_ID}, {"id": NewAmiFreeTrial.LEGAL_TERM_ID}, ], agreementProposalIdentifier=NewAmiFreeTrial.AGREEMENT_PROPOSAL_IDENTIFIER, ) agreement_request_id = create_response["agreementRequestId"] print("Agreement request created. AgreementRequestId: " + agreement_request_id) accept_response = client.accept_agreement_request( agreementRequestId=agreement_request_id ) print( "Agreement request with freeTrialPricingTerm accepted. AgreementId: " + accept_response["agreementId"] ) if __name__ == "__main__": NewAmiFreeTrial.create_and_accept_ami_free_trial_agreement_request()