View a markdown version of this page

Crea un nuovo contratto di prova gratuita AMI utilizzando un AWS SDK - AWS Esempi di codice SDK

Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Crea un nuovo contratto di prova gratuita AMI utilizzando un AWS SDK

I seguenti esempi di codice mostrano come creare un nuovo contratto di prova gratuito AMI.

Java
SDK per Java 2.x
Nota

C'è altro su GitHub. Trova l’esempio completo e scopri come eseguire la configurazione e l’esecuzione nel repository di esempi di codice dell’API Marketplace AWS.

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 per JavaScript (v3)
Nota

C'è altro da fare. GitHub Trova l’esempio completo e scopri come eseguire la configurazione e l’esecuzione nel repository di esempi di codice dell’API Marketplace AWS.

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 per Python (Boto3)
Nota

C'è altro su GitHub. Trova l’esempio completo e scopri come eseguire la configurazione e l’esecuzione nel repository di esempi di codice dell’API Marketplace AWS.

""" 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()