Codebeispiele für die SaaS-Produktintegration - AWS Marketplace

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.

Codebeispiele für die SaaS-Produktintegration

Die folgenden Codebeispiele können Ihnen helfen, Ihr SaaS-Produkt (Software as a Service) mit den AWS Marketplace APIs zu integrieren, die für die Veröffentlichung und Wartung Ihres Produkts erforderlich sind.

ResolveCustomerCodebeispiel

Das folgende Codebeispiel ist für alle Preismodelle relevant. Das Python-Beispiel tauscht ein x-amzn-marketplace-token Token gegen ein CustomerIdentifierProductCode, und ausCustomerAWSAccountId. Das CustomerAWSAccountId ist die AWS-Konto ID, die dem Abonnement zugeordnet ist. Dieser Code wird in einer Anwendung auf Ihrer Registrierungswebsite ausgeführt, wenn Sie von der dorthin weitergeleitet werden AWS Marketplace Management Portal. Die Umleitung ist eine POST-Anforderung, die das Token enthält.

Weitere Informationen ResolveCustomer dazu finden Sie ResolveCustomerin der AWS Marketplace Metering Service API-Referenz.

# 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

Beispielantwort

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

GetEntitlementCode-Beispiel

Das folgende Codebeispiel ist relevant für SaaS-Produkte mit den Preismodellen Vertrag und Vertrag mit Verbrauch. Im Python-Beispiel wird überprüft, ob ein Kunde über eine aktive Berechtigung verfügt.

Weitere Informationen zu GetEntitlement finden Sie GetEntitlementin der AWS Marketplace Entitlement Service API-Referenz.

# 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

Beispielantwort

Der zurückgegebene Wert entspricht den Dimensionen, die erstellt wurden, als Sie das Produkt in der AWS Marketplace Management Portal erstellt haben.

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

BatchMeterUsageCode-Beispiel

Das folgende Codebeispiel ist relevant für SaaS-Abonnements und Verträge mit Verbrauchspreismodellen, jedoch nicht für SaaS-Vertragsprodukte ohne Verbrauch. Das Python-Beispiel sendet einen Messdatensatz an AWS Marketplace , um Ihren Kunden pay-as-you-go Gebühren in Rechnung zu stellen.

# 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)

Weitere Informationen BatchMeterUsage dazu finden Sie BatchMeterUsagein der AWS Marketplace Metering Service API-Referenz.

Beispielantwort

{ '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 } ] }

BatchMeterUsagemit einem Codebeispiel für die Kennzeichnung der Nutzungszuweisung (optional)

Das folgende Codebeispiel ist relevant für ein SaaS-Abonnement und einen Vertrag mit Verbrauchspreismodellen, jedoch nicht für SaaS-Vertragsprodukte ohne Verbrauch. Das Python-Beispiel sendet einen Messdatensatz mit entsprechenden Nutzungszuweisungs-Tags an AWS Marketplace , um Ihren Kunden pay-as-you-go Gebühren in Rechnung zu stellen.

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

Weitere Informationen zu BatchMeterUsage finden Sie BatchMeterUsagein der AWS Marketplace Metering Service API-Referenz.

Beispielantwort

{ "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": [] } ] }