首页 > 解决方案 > 无法在成本浏览器过滤器中指定“非”运算符

问题描述

我正在尝试使用 aws-sdk-js 从成本资源管理器中查询数据。一切正常,直到我尝试将 a 添加Not到我的过滤器并遇到此错误 -

TypeError: Cannot redefine property: Not
    at Function.defineProperty (<anonymous>)
    at Object.get Not [as Not] (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/client-cost-explorer-node/model/shapes/_Expression.ts:18:14)
    at JsonBuilder.format (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/json-builder/src/index.ts:62:57)
    at JsonBuilder.format (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/json-builder/src/index.ts:62:37)
    at JsonBuilder.build (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/json-builder/src/index.ts:36:32)
    at JsonRpcSerializer.serialize (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/protocol-json-rpc/src/JsonRpcSerializer.ts:29:33)
    at Object.<anonymous> (/Users/yaron/code/cloud-cost-fetcher/node_modules/@aws-sdk/middleware-serializer/src/index.ts:24:39)
    at step (/Users/yaron/code/cloud-cost-fetcher/node_modules/tslib/tslib.js:141:27)
    at Object.next (/Users/yaron/code/cloud-cost-fetcher/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/Users/yaron/code/cloud-cost-fetcher/node_modules/tslib/tslib.js:112:62)

当我使用 AWS CLI 时,相同的过滤器工作得非常好,所以我怀疑这与成本浏览器客户端实施有关。

这是我的代码中产生此错误的相关内容-

import { GetCostAndUsageCommand } from '@aws-sdk/client-cost-explorer-node/commands/GetCostAndUsageCommand'
import { CostExplorerClient } from '@aws-sdk/client-cost-explorer-node/CostExplorerClient'
import AWS from 'aws-sdk'


  const costExplorer = new CostExplorerClient({
    region: 'us-east-1',
    credentials: new AWS.SharedIniFileCredentials({ profile: billingProfile }),
  })
  const getCostAndUsageCommand = new GetCostAndUsageCommand({
    TimePeriod,
    Granularity: 'MONTHLY',
    GroupBy: [
      {
        Type: 'TAG',
        Key: '<TAG_NAME>',
      },
    ],
    Filter: {
      Not: {
        Dimensions: {
          Key: 'LINKED_ACCOUNT',
          Values: ['<ACCOUNT_NUMBER'],
        },
      },
    },
    Metrics: [metricsType],
  })

我正在使用以下 aws npm 模块 -

"@aws-sdk/client-cost-explorer-node": "^0.1.0-preview.2",
"aws-sdk": "^2.747.0",    

任何帮助将不胜感激。

标签: aws-sdk-js

解决方案


我已经在 aws-sdk-js 存储库上发布了相同的问题,并从一位维护者那里得到了一个快速而有用的答案。似乎此模块已弃用,应更改为另一个模块,在此处发布此答案,以防将来有人需要此信息。


推荐阅读