View a markdown version of this page

Erstellen Sie eine neue Vereinbarung für eine kostenlose AMI-Testversion mit einem AWS SDK - AWS SDK-Codebeispiele

Weitere AWS SDK-Beispiele sind im GitHub Repo AWS Doc SDK Examples verfügbar.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Erstellen Sie eine neue Vereinbarung für eine kostenlose AMI-Testversion mit einem AWS SDK

Die folgenden Codebeispiele zeigen, wie Sie eine neue Vereinbarung für eine kostenlose AMI-Testversion erstellen.

Java
SDK für Java 2.x
Anmerkung

Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das Repository der Codebibliothek der AWS Marketplace -API-Referenz einrichten und ausführen.

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 für JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das Repository der Codebibliothek der AWS Marketplace -API-Referenz einrichten und ausführen.

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 für Python (Boto3)
Anmerkung

Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das Repository der Codebibliothek der AWS Marketplace -API-Referenz einrichten und ausführen.

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