SaaS 제품 통합 코드 예제 - AWS Marketplace

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

SaaS 제품 통합 코드 예제

다음 코드 예제는 SaaS (Software as a Service) 제품을 제품 게시 및 유지 관리에 필요한 AWS Marketplace API와 통합하는 데 도움이 될 수 있습니다.

ResolveCustomer 코드 예제

다음 코드 예제는 모든 요금 모델과 관련이 있습니다. Python 예제는 CustomerIdentifier, ProductCodeCustomerAWSAccountId에 대한 x-amzn-marketplace-token 토큰을 교환합니다. CustomerAWSAccountId는 구독과 연결된 AWS 계정 ID입니다. 이 코드는 AWS Marketplace Management Portal에서 리디렉션될 때 등록 웹 사이트의 애플리케이션에서 실행됩니다. 리디렉션은 토큰을 포함하는 POST 요청입니다.

에 대한 ResolveCustomer 자세한 내용은 AWS Marketplace 미터링 서비스 ResolveCustomerAPI 참조를 참조하십시오.

# 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 Management Portal에서 제품을 생성할 때 생성된 차원과 일치합니다.

{ "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 청구하기 위해 미터링 레코드를 전송합니다. 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)

에 대한 BatchMeterUsage 자세한 내용은 AWS Marketplace 미터링 서비스 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 전송하여 고객에게 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")

에 대한 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": [] } ] }