当我想使用 DescribeStacks API 调用时,我需要什么权限?

1 分钟阅读
0

我想解决我在调用 DescribeStacks API 时遇到的 Access Denied(访问被拒绝)错误。

简短描述

当运行 DescribeStacks AWS 命令行界面 (AWS CLI) 命令时,可能会收到以下错误:

“An error occurred (AccessDenied) when calling the DescribeStacks operation: User: arn:aws:sts::#AccountId:assumed-role/#RoleName/xxx is not authorized to perform: cloudformation:ListStacks on resource: arn:aws:cloudformation:us-east-1:#AccountId:stack/*/* because no identity-based policy allows the cloudformation:ListStacks action" error appears when role "#RoleName" does not have the "cloudformation:ListStacks" action.(调用 DescribeStacks 操作时出错 (AccessDenied):当角色“#RoleName”没有“cloudformation:ListStacks”操作时,会出现以下错误:用户 arn:aws:sts::#AccountId:assumed-role/#RoleName/xxx 无权对资源 arn:aws:cloudformation:us-east-1:#AccountId:stack/*/* 执行 cloudformation:ListStacks,因为没有基于身份的策略允许 cloudformation:ListStacks 操作)”

**注意:**如果在运行 AWS CLI 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

使用 AWS 管理控制台时,您可能会看到相应的“Failed to load stacks(无法加载堆栈)”错误。要验证这是否是权限相关问题,请检查 AWS CloudTrail 事件,然后筛选 ListStacks API 调用。

解决方法

当角色没有执行 cloudformation:ListStacks 操作所需的权限时,就会出现前面描述的错误。
**注意:**如果未指定堆栈名称,则 DescribeStack 的权限还需要对 ListStacks 的权限。

更新权限策略以允许访问 ListStacks

在 AWS 管理控制台上完成以下步骤以修改角色的权限策略:

  1. 以管理员身份登录 AWS 管理控制台

  2. 在搜索栏中输入 IAM。在 Services(服务)下,选择 IAM 作为 AWS 管理控制台上的服务。

  3. 在左侧导航窗格中,选择 Roles(角色)选项卡。

  4. 在搜索栏中输入角色名称,然后选择角色名称超链接(以蓝色突出显示)。

  5. Permissions(权限)选项卡下,为任何一种客户管理型策略类型或客户内联策略选择 + 图标。然后,选择 Edit(编辑)按钮。有关详细信息,请参阅编辑 IAM 策略

  6. 查看修改 #PolicyName 中的权限网页。确保它包含 cloudformation:ListStacks。更新后的政策如下所示:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "VisualEditor",
          "Effect": "Allow",
          "Action": [
            "cloudformation:DescribeStacks",
            "cloudformation:ListStacks"
          ],
          "Resource": "*"
        }
      ]
    }
  7. 选择 Next(下一步)。然后,选择 Save changes(保存更改)按钮以实施策略更改。

  8. 测试 aws cloudformation describe-stacks 命令以确保其成功运行。

相关信息

DescribeStacks

describe-stacks

ListStacks

AWS 官方
AWS 官方已更新 1 年前