Esempi di codice per l'integrazione di prodotti SaaS - Marketplace AWS

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

Esempi di codice per l'integrazione di prodotti SaaS

I seguenti esempi di codice possono aiutarti a integrare il tuo prodotto SaaS (Software as a Service) con le Marketplace AWS API necessarie per la pubblicazione e la manutenzione del prodotto.

ResolveCustomeresempio di codice

Il seguente esempio di codice è rilevante per tutti i modelli di prezzo. L'esempio Python scambia un x-amzn-marketplace-token token con un CustomerIdentifierProductCode, e. CustomerAWSAccountId CustomerAWSAccountIdÈ l' Account AWS ID associato all'abbonamento. Questo codice viene eseguito in un'applicazione sul sito Web di registrazione, quando si viene reindirizzati lì da. Portale di gestione Marketplace AWS Il reindirizzamento è una richiesta POST che include il token.

Per ulteriori informazioni ResolveCustomerin meritoResolveCustomer, consulta la sezione Marketplace AWS Metering Service API Reference.

# Import AWS Python SDK and urllib.parse import boto3 import urllib.parse as urlparse # Resolving Customer Registration Token formFields = urlparse.parse_qs(postBody) regToken = formFields['x-amzn-marketplace-token'][0] # If regToken present in POST request, exchange for customerID if (regToken): marketplaceClient = boto3.client('meteringmarketplace') customerData = marketplaceClient.resolve_customer(RegistrationToken=regToken) productCode = customerData['ProductCode'] customerID = customerData['CustomerIdentifier'] customerAWSAccountId = customerData['CustomerAWSAccountId'] # TODO: Store customer information # TODO: Validate no other accounts share the same customerID

Example response

{ 'CustomerIdentifier': 'string', 'CustomerAWSAccountId':'string', 'ProductCode': 'string' }

GetEntitlementesempio di codice

Il seguente esempio di codice è rilevante per i prodotti SaaS con contratto e contratto SaaS con modello di prezzo al consumo. L'esempio Python verifica che un cliente disponga di un'autorizzazione attiva.

Per ulteriori informazioni in meritoGetEntitlement, consulta l'articolo Marketplace AWS Entitlement GetEntitlementService API Reference.

# Import AWS Python SDK import boto3 marketplaceClient = boto3.client('marketplace-entitlement', region_name='us-east-1') # Filter entitlements for a specific customerID # # productCode is supplied after the AWS Marketplace Ops team has published # the product to limited # # customerID is obtained from the ResolveCustomer response entitlement = marketplaceClient.get_entitlements({ 'ProductCode': 'productCode', 'Filter' : { 'CUSTOMER_IDENTIFIER': [ 'customerID', ] }, 'NextToken' : 'string', 'MaxResults': 123 }) # TODO: Verify the dimension a customer is subscribed to and the quantity, # if applicable

Example response

Il valore restituito corrisponde alle dimensioni create quando è stato creato il prodotto in. Portale di gestione Marketplace AWS

{ "Entitlements": [ { "CustomerIdentifier": "string", "Dimension": "string", "ExpirationDate": number, "ProductCode": "string", "Value": { "BooleanValue": boolean, "DoubleValue": number, "IntegerValue": number, "StringValue": "string" } } ], "NextToken": "string" }

BatchMeterUsageesempio di codice

Il seguente esempio di codice è rilevante per i modelli di abbonamento e contratto SaaS con prezzi al consumo, ma non per i prodotti contrattuali SaaS senza consumo. L'esempio di Python invia un record di misurazione per addebitare Marketplace AWS le commissioni ai clienti. pay-as-you-go

# NOTE: Your application will need to aggregate usage for the # customer for the hour and set the quantity as seen below. # AWS Marketplace can only accept records for up to an hour in the past. # # productCode is supplied after the AWS Marketplace Ops team has # published the product to limited # # customerID is obtained from the ResolveCustomer response # Import AWS Python SDK import boto3 usageRecord = [ { 'Timestamp': datetime(2015, 1, 1), 'CustomerIdentifier': 'customerID', 'Dimension': 'string', 'Quantity': 123 } ] marketplaceClient = boto3.client('meteringmarketplace') response = marketplaceClient.batch_meter_usage(usageRecord, productCode)

Per ulteriori informazioni BatchMeterUsagein meritoBatchMeterUsage, consulta la sezione Marketplace AWS Metering Service API Reference.

Example response

{ 'Results': [ { 'UsageRecord': { 'Timestamp': datetime(2015, 1, 1), 'CustomerIdentifier': 'string', 'Dimension': 'string', 'Quantity': 123 }, 'MeteringRecordId': 'string', 'Status': 'Success' | 'CustomerNotSubscribed' | 'DuplicateRecord' }, ], 'UnprocessedRecords': [ { 'Timestamp': datetime(2015, 1, 1), 'CustomerIdentifier': 'string', 'Dimension': 'string', 'Quantity': 123 } ] }

BatchMeterUsagecon esempio di codice di etichettatura per l'allocazione dell'utilizzo (opzionale)

Il seguente esempio di codice è rilevante per un abbonamento e un contratto SaaS con modelli di prezzi al consumo, ma non per i prodotti contrattuali SaaS senza consumo. L'esempio di Python invia un record di misurazione con i tag di allocazione dell'uso appropriati per addebitare le Marketplace AWS commissioni ai clienti. pay-as-you-go

# NOTE: Your application will need to aggregate usage for the # customer for the hour and set the quantity as seen below. # AWS Marketplace can only accept records for up to an hour in the past. # # productCode is supplied after the AWS Marketplace Ops team has # published the product to limited # # customerID is obtained from the ResolveCustomer response # Import AWS Python SDK import boto3 import time usageRecords = [ { "Timestamp": int(time.time()), "CustomerIdentifier": "customerID", "Dimension": "Dimension1", "Quantity":3, "UsageAllocations": [ { "AllocatedUsageQuantity": 2, "Tags": [ { "Key": "BusinessUnit", "Value": "IT" }, { "Key": "AccountId", "Value": "123456789" }, ] }, { "AllocatedUsageQuantity": 1, "Tags": [ { "Key": "BusinessUnit", "Value": "Finance" }, { "Key": "AccountId", "Value": "987654321" }, ] }, ] } ] marketplaceClient = boto3.client('meteringmarketplace') response = marketplaceClient.batch_meter_usage(UsageRecords=usageRecords, ProductCode="testProduct")

Per ulteriori informazioni in meritoBatchMeterUsage, consulta l'API BatchMeterUsageReference.AWS Marketplace Metering Service

Example response

{ "Results": [ { "Timestamp": "1634691015", "CustomerIdentifier": "customerID", "Dimension": "Dimension1", "Quantity":3, "UsageAllocations": [ { "AllocatedUsageQuantity": 2, "Tags": [ { "Key": "BusinessUnit", "Value": "IT" }, { "Key": "AccountId", "Value": "123456789" }, ] }, { "AllocatedUsageQuantity": 1, "Tags": [ { "Key": "BusinessUnit", "Value": "Finance" }, { "Key": "AccountId", "Value": "987654321" }, ] }, ] }, "MeteringRecordId": "8fjef98ejf", "Status": "Success" }, ], "UnprocessedRecords": [ { "Timestamp": "1634691015", "CustomerIdentifier": "customerID", "Dimension": "Dimension1", "Quantity":3, "UsageAllocations": [] } ] }