【问题标题】:user is not authorized to perform: ce:GetCostAndUsage用户无权执行:ce:GetCostAndUsage
【发布时间】:2018-11-07 01:53:43
【问题描述】:

我正在使用 boto3,尝试使用 Cost Exploer 来获取成本和使用情况

import boto3
client = boto3.client('ce')
client.get_cost_and_usage()

已向用户授予以下权限

  "aws-portal:ViewUsage",
  "aws-portal:ViewBilling"

但总是报错

调用 GetCostAndUsage 操作时发生错误 (AccessDeniedException):用户:arn:aws:iam::123456789:user/User1 无权执行:ce:GetCostAndUsage on resource:arn:aws:ce: us-east-1:123456789

【问题讨论】:

    标签: boto3 amazon-iam


    【解决方案1】:

    刚刚从这里找到答案 https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-example-policies.html#example-policy-ce-api

    示例 11:查看成本和使用情况

    要允许 IAM 用户使用 AWS Cost Explorer API,请使用以下策略授予他们访问权限:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "ce:*"
          ],
          "Resource": [
            "*"
          ]
        }
      ]
    }
    

    【讨论】:

      【解决方案2】:

      我找不到现有的小范围只读策略来获取使用情况统计信息。

      通过网络“可视化编辑器”创建新策略也很容易:

      1. 导航到 IAM -> 策略 -> 创建策略
      2. 选择服务为Cost Explorer Service
      3. 勾选[X] Read权限
      4. 点击查看
      5. 为其命名,例如MyCostExplorerRead
      6. 将新创建的策略分配给您的用户

      【讨论】:

      • 哇,这节省了我数小时的调试时间。谢谢
      猜你喜欢
      • 2016-03-18
      • 2021-02-26
      • 1970-01-01
      • 2016-09-26
      • 2016-02-16
      • 2016-04-19
      • 2019-01-22
      • 2021-02-08
      • 1970-01-01
      相关资源
      最近更新 更多