SaaS 製品統合のコード例 - AWS Marketplace

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SaaS 製品統合のコード例

次のコード例は、Software as a Service (SaaS) 製品の公開およびメンテナンスに必要な AWS Marketplace API と SaaS 製品を統合するのに役立てることを目的として役立ちます。

ResolveCustomer コード例

次のコード例は、すべての料金モデルに関連しています。Python の例によって、x-amzn-marketplace-token トークンが CustomerIdentifierProductCodeCustomerAWSAccountId に交換されます。CustomerAWSAccountId はサブスクリプションに関連付けられた AWS アカウント ID です。このコードは、AWS Marketplace 管理ポータル からリダイレクトされたときに、登録ウェブサイト上のアプリケーションで実行されます。リダイレクトは、トークンを含む POST リクエストです。

ResolveCustomer の詳細については、「AWS Marketplace Metering Service API リファレンス」の「ResolveCustomer」を参照してください。

# 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

レスポンスの例

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

GetEntitlement コード例

次のコード例は、契約を持つ SaaS 製品および消費料金モデルを持つ SaaS 契約に関連しています。Python の例では、顧客がアクティブな使用権限を持っていることを確認します。

GetEntitlement について詳しくは、AWS Marketplace 使用権限管理サービス API リファレンスの「GetEntitlement」を参照してください。

# 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

レスポンスの例

戻り値は、AWS Marketplace 管理ポータル で製品を作成したときに作成されたディメンションに対応します。

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

BatchMeterUsage コード例

次のコード例は、SaaS サブスクリプションおよび消費料金モデルを使用した契約に関連しますが、消費のない SaaS 契約製品には該当しません。Python の例では、従量制料金を顧客に請求するために、計測レコードを AWS Marketplace に送信します。

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

BatchMeterUsage の詳細については、AWS Marketplace Metering Service API リファレンスの「BatchMeterUsage」を参照してください。

レスポンスの例

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

使用量割り当てタグ付きの BatchMeterUsage のコード例 (オプション)

次のコード例は、SaaS サブスクリプションおよび消費料金モデルを使用した契約に関連しますが、追加使用量のない SaaS 契約製品には該当しません。Python の例では、従量制料金を顧客に請求するために、適切な使用量割り当てタグを含む計測レコードを AWS Marketplace に送信します。

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

BatchMeterUsage の詳細については、AWS Marketplace Metering Service API リファレンスの「BatchMeterUsage」を参照してください。

レスポンスの例

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