首页 > 解决方案 > 如何判断一个人的工作成本是多少

问题描述

有没有办法知道个人培训工作的成本是多少?

我可以在计费仪表板中看到每日/每小时费用,这是一个很好的代理。我也查看了使用报告,但没有看到将 UsageValues 相加的方法,也没有看到使用报告中的标签。

标签: amazon-sagemaker

解决方案


当您调用DescribeTrainingJob API 调用时,您将获得以下值:TrainingStartTime 和 TrainingEndTime。您需要为这些时间之间的时间间隔付费。

现在您需要在 ResourceConfig 下(在同一 API 调用输出中)获取接下来的两个值来完成成本计算:InstanceType 和 InstanceCount。

最后,您可以查询您正在使用的 InstanceType 的定价 API,并获取您正在运行的区域的价格。

import boto3
pricing_client = boto3.client('pricing', region_name='us-east-1')
filterValue = instanceType + "-Training"

response = pricing_client.get_products(
    ServiceCode='AmazonSageMaker',
    Filters=[
        {
            'Type': 'TERM_MATCH',
            'Field': 'instanceType',
            'Value': filterValue
        },
    ]
)
## TODO: fix this line to take the right region and not the first
python_dict = json.loads(response['PriceList'][0])

pricePerHour = next(iter(next(iter(python_dict['terms']['OnDemand'].values()))["priceDimensions"].values()))["pricePerUnit"]['USD']
return float(pricePerHour)

推荐阅读