当我拥有 AWS 积分时,为什么 Cost Explorer 客户端显示错误的结果?

Oro*_*vid 4 javascript amazon-web-services node.js aws-sdk-js aws-sdk-js-v3

使用 AWS 控制台 --> AWS Cost Management --> Cost Explorer 时 - 我得到以下值:

在此输入图像描述

当我使用@aws-sdk/client-cost-explorer“EC2 - 其他”和“Amazon Load Balancer”时,我得到不同的结果。

配置:

import { CostExplorerClient, GetCostAndUsageCommand } from '@aws-sdk/client-cost-explorer';

const client = new CostExplorerClient({
        region,
        credentials: {
          accessKeyId,
          secretAccessKey
        }
      });
    
      const params = {
        TimePeriod: {
          Start: startDate,
          End: endDate
        },
        Filter: {
         Dimensions: {
           Key: 'SERVICE',
           Values: [
             'EC2 - Other', 'Amazon ElastiCache'
           ]
         }
        },
        GroupBy: [
          {
            Type: 'DIMENSION',
            Key: 'SERVICE',
          },
        ],
        Granularity: 'DAILY',
        Metrics: [
          'BLENDED_COST',
          'UNBLENDED_COST',
          'AMORTIZED_COST', 
          'NET_AMORTIZED_COST',             
     ] 
      };
      const command = new GetCostAndUsageCommand(params);
      try {
        const data = await client.send(command);
        log.info(data);
Run Code Online (Sandbox Code Playgroud)

结果是:

GroupDefinitions: [
    {
      "Key": "AZ",
      "Type": "DIMENSION"
    },
    {
      "Key": "SERVICE",
      "Type": "DIMENSION"
    }
  ]
  --
  ResultsByTime: [
    {
      "Estimated": false,
      "Groups": [
        {
          "Keys": [
            "NoAZ",
            "Amazon ElastiCache"
          ],
          "Metrics": {
            "AmortizedCost": {
              "Amount": "-122.4",
              "Unit": "USD"
            },
            "BlendedCost": {
              "Amount": "-122.4",
              "Unit": "USD"
            },
            "NetAmortizedCost": {
              "Amount": "-122.4",
              "Unit": "USD"
            },
            "UnblendedCost": {
              "Amount": "-122.4",
              "Unit": "USD"
            }
          }
        },
        {
          "Keys": [
            "NoAZ",
            "EC2 - Other"
          ],
          "Metrics": {
            "AmortizedCost": {
              "Amount": "0.2467152681",
              "Unit": "USD"
            },
            "BlendedCost": {
              "Amount": "0.2467152681",
              "Unit": "USD"
            },
            "NetAmortizedCost": {
              "Amount": "0.2467152681",
              "Unit": "USD"
            },
            "UnblendedCost": {
              "Amount": "0.2467152681",
              "Unit": "USD"
            }
          }
        },
        {
          "Keys": [
            "us-east-1",
            "Amazon ElastiCache"
          ],
          "Metrics": {
            "AmortizedCost": {
              "Amount": "122.4",
              "Unit": "USD"
            },
            "BlendedCost": {
              "Amount": "122.4",
              "Unit": "USD"
            },
            "NetAmortizedCost": {
              "Amount": "122.4",
              "Unit": "USD"
            },
            "UnblendedCost": {
              "Amount": "122.4",
              "Unit": "USD"
            }
          }
        }
      ],
      "TimePeriod": {
        "End": "2022-05-01",
        "Start": "2022-04-01"
      },
      "Total": {}
    },
    {
      "Estimated": true,
      "Groups": [
        {
          "Keys": [
            "NoAZ",
            "Amazon ElastiCache"
          ],
          "Metrics": {
            "AmortizedCost": {
              "Amount": "-89.59",
              "Unit": "USD"
            },
            "BlendedCost": {
              "Amount": "-89.59",
              "Unit": "USD"
            },
            "NetAmortizedCost": {
              "Amount": "-89.59",
              "Unit": "USD"
            },
            "UnblendedCost": {
              "Amount": "-89.59",
              "Unit": "USD"
            }
          }
        },
        {
          "Keys": [
            "NoAZ",
            "EC2 - Other"
          ],
          "Metrics": {
            "AmortizedCost": {
              "Amount": "0.1766760069",
              "Unit": "USD"
            },
            "BlendedCost": {
              "Amount": "0.1766760069",
              "Unit": "USD"
            },
            "NetAmortizedCost": {
              "Amount": "0.1766760069",
              "Unit": "USD"
            },
            "UnblendedCost": {
              "Amount": "0.1766760069",
              "Unit": "USD"
            }
          }
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,“Amazon ElastiCache”的量对于所有指标都是正确的,但EC2-Other的量对于所有指标都是错误的。

我们的账户当前正在使用 AWS 积分。

我正在寻找用于此 SDK 的正确参数,以便接收每项服务的每日/每月使用情况。

Erm*_*ary 5

默认情况下,控制台中的 Cost Explorer UI 应用一个排除退款信用费用类型的过滤器(您可以在过滤器列表的中间看到)。

当您使用 AWS 积分时,您当前的GetCostAndUsageCommand积分将包含减少Amount价值的积分。

您将需要复制已在 UI 中应用的相同排除过滤器。这将Amount根据控制台中显示的内容增加您的值。

NOT 您可以使用表达式排除退款和/或积分(如适用)。这已从GetCostAndUsageCommandInput文档链接到。

尝试:

const params = {
    TimePeriod: {
        Start: startDate,
        End: endDate
    },
    Filter: {
        Not: {
            Dimensions: {
                Key: "RECORD_TYPE",
                Values: ["Refund", "Credit"]
            }
        },
        Dimensions: {
            Key: 'SERVICE',
            Values: [
                'EC2 - Other', 'Amazon ElastiCache'
            ]
        }
    },
    GroupBy: [{
        Type: 'DIMENSION',
        Key: 'SERVICE',
    }, ],
    Granularity: 'DAILY',
    Metrics: [
        'BLENDED_COST',
        'UNBLENDED_COST',
        'AMORTIZED_COST',
        'NET_AMORTIZED_COST',
    ]
};
Run Code Online (Sandbox Code Playgroud)