本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
中 AMI 產品的成本分配標記 AWS Marketplace
AWS Marketplace 支援 Amazon Machine Image (AMI) 型軟體產品的成本分配標記。新的和現有的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體標籤會根據對應的 AWS Marketplace AMI 用量自動填入。您可以使用啟用的成本分配標籤,透過 AWS 成本和用量報告、 AWS 預算或其他雲端支出分析工具 AWS Cost Explorer來識別和追蹤 AMI 用量。
提供 AMI 的廠商也可以根據產品的特定資訊,在 AMI 型產品的計量中記錄其他自訂標籤。如需詳細資訊,請參閱使用成本分配標記。
您可以使用標籤來整理您的資源,而成本分配標籤可以用來詳細追蹤您的 AWS 成本。啟用成本分配標籤後, AWS 會使用成本分配標籤來整理成本分配報告上的資源成本,讓您更輕鬆地分類和追蹤 AWS 成本。
成本分配標記只會從在 Billing and Cost Management 主控台中啟用標籤的時間開始追蹤成本。只有擁有適當許可的 AWS 帳戶 擁有者、 AWS Organizations 管理帳戶擁有者和使用者才能存取帳戶的 Billing and Cost Management 主控台。無論您是否使用成本分配標記,您支付的費用都不會變更。無論您是否使用成本分配標籤,都不會影響您 AMI 型軟體產品的功能。
跨多個執行個體追蹤一個 AMI 的成本分配標籤
每個為 AWS Marketplace AMI 訂閱啟動的 Amazon EC2 執行個體在 AWS 成本和用量報告中都有對應的 AWS Marketplace 軟體用量明細項目。您的 AWS Marketplace 用量一律會反映套用至對應 Amazon EC2 執行個體的特定標籤。這可讓您根據在執行個體層級指派的不同標籤值來區分 AWS Marketplace 用量成本。
您也可以使用 Cost Explorer 或 AWS Cost and Usage 報告來加總標籤型用量成本,以等於帳單中反映的 AMI 軟體用量費用。
尋找具有成本分配標記執行個體的預算
如果您已在 Billing and Cost Management 主控台中的多個 Amazon EC2 執行個體上篩選成本分配標籤的作用中預算,則可能很難找到所有預算。下列 Python 指令碼會傳回預算清單,其中包含目前 AWS Marketplace 中的 Amazon EC2 執行個體 AWS 區域。
您可以使用此指令碼來了解對預算的潛在影響,以及此變更可能發生超支的位置。請注意,計費金額不會變更,但成本分配會更準確地反映,這可能會影響預算。
#! /usr/bin/python import boto3 session = boto3.Session() b3account=boto3.client('sts').get_caller_identity()['Account'] print("using account {} in region {}".format(b3account,session.region_name)) def getBudgetFilters(filtertype): ''' Returns budgets nested within the filter values [filter value][budeget name]. The filtertype is the CostFilter Key such as Region, Service, TagKeyValue. ''' budget_client = session.client('budgets') budgets_paginator = budget_client.get_paginator('describe_budgets') budget_result = budgets_paginator.paginate( AccountId=b3account ).build_full_result() returnval = {} if 'Budgets' in budget_result: for budget in budget_result['Budgets']: for cftype in budget['CostFilters']: if filtertype == cftype: for cfval in budget['CostFilters'][cftype]: if cfval in returnval: if not budget['BudgetName'] in returnval[cfval]: returnval[cfval].append(budget['BudgetName']) else: returnval[cfval] = [ budget['BudgetName'] ] return returnval def getMarketplaceInstances(): ''' Get all the Amazon EC2 instances which originated with AWS Marketplace. ''' ec2_client = session.client('ec2') paginator = ec2_client.get_paginator('describe_instances') returnval = paginator.paginate( Filters=[{ 'Name': 'product-code.type', 'Values': ['marketplace'] }] ).build_full_result() return returnval def getInstances(): mp_instances = getMarketplaceInstances() budget_tags = getBudgetFilters("TagKeyValue") cost_instance_budgets = [] for instance in [inst for resrv in mp_instances['Reservations'] for inst in resrv['Instances'] if 'Tags' in inst.keys()]: for tag in instance['Tags']: # combine the tag and value to get the budget filter string str_full = "user:{}${}".format(tag['Key'], tag['Value']) if str_full in budget_tags: for budget in budget_tags[str_full]: if not budget in cost_instance_budgets: cost_instance_budgets.append(budget) print("\r\nBudgets containing tagged Marketplace EC2 instances:") print( '\r\n'.join([budgetname for budgetname in cost_instance_budgets]) ) if __name__ == "__main__": getInstances()
範例輸出
Using account123456789012in region us-east-2 Budgets containing tagged Marketplace EC2 instances: EC2 simple MP-test-2
相關主題
如需詳細資訊,請參閱下列主題:
-
《 AWS Billing 使用者指南》中的使用成本分配標籤。
-
AWS Billing 《 使用者指南》中的啟用 AWS 產生的成本分配標籤。
-
《Amazon EC2 使用者指南》中的標記您的 Amazon EC2 資源。