【问题标题】:User is not authorized to perform: cloudformation:CreateStack用户无权执行:cloudformation:CreateStack
【发布时间】:2016-03-18 04:10:20
【问题描述】:

我正在尝试使用 Serverless 创建 AWS Lambda,在使用命令 serverless project create 创建项目时遇到以下错误。

AccessDenied: User: arn:aws:iam::XXXXXXXXX:user/XXXXXXXXX is not authorized to perform: cloudformation:CreateStack on resource: arn:aws:cloudformation:us-east-1:XXXXXXXXX:stack/XXXXXXXXX-development-r/*

我创建了一个用户并授予该用户以下权限。

  1. AWSLambdaFullAccess
  2. AmazonS3FullAccess
  3. CloudFront 完全访问
  4. AWSCloudFormationReadOnlyAccess(没有要授予的AWSCloudFormationFullAccess

我该如何继续?我还必须授予什么权限?

【问题讨论】:

  • 自 2019 年 7 月 26 日起,现在有一个 AWSCloudFormationFullAccess 政策。

标签: amazon-web-services amazon-iam amazon-cloudformation


【解决方案1】:

您提到的最接近的是AWSCloudFormationReadOnlyAccess,但显然这是只读的,您需要cloudformation:CreateStack。添加以下内容作为用户政策

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

您完全有可能需要更多权限 - 例如,启动 EC2 实例、(重新)配置安全组等。

【讨论】:

  • 我怎样才能授予cloudformation:CreateStack?我使用的是 AWS UI 而不是 CLI。
  • 您将我提供的文本粘贴为自定义用户策略。
  • 您可以使用 Aws 策略生成器来生成此具体策略或任何其他
  • 我觉得很奇怪,这在他们的拖放 UI 中是不可用的,谢谢。
  • 我按照您的说明将其添加为内联策略,但现在当我尝试运行 describe-stacks 时出现类似错误。如何修改此策略以允许描述堆栈?
【解决方案2】:

@tedder42 说了什么,但我还必须在我的组策略中添加以下内容,然后才能从 Visual Studio 内部部署到 lambda。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:CreateChangeSet",
                "cloudformation:ListStacks",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

【讨论】:

  • 如果你打算做servlerless info,你也需要cloudformation:DescribeStacks
  • 这个答案应该被投赞成票并向@pdeschen +1 说如果您尝试使用无服务器部署,您还需要添加cloudformation:DescribeStacks。我还必须添加cloudformation:DescribeStackResourcecloudformation:ValidateTemplate
  • 我还添加了这两个操作:cloudformation:DescribeStackEvents cloudformation:DeleteStack 因为我需要允许,所以我的用户也删除了堆栈。
【解决方案3】:

根据我最近的经验,所需的政策是

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1449904348000",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:CreateChangeSet",
                "cloudformation:ListStacks",
                "cloudformation:UpdateStack",
                "cloudformation:DescribeStacks",
                "cloudformation:DescribeStackResource",
                "cloudformation:DescribeStackEvents",
                "cloudformation:ValidateTemplate",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

【讨论】:

    【解决方案4】:

    我无法让上面显示的较短版本工作;对我来说解决问题的是稍微扩展@mancvso 的答案以添加"cloudformation:GetTemplateSummary"

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "Stmt1449904348000",
                "Effect": "Allow",
                "Action": [
                    "cloudformation:CreateStack",
                    "cloudformation:CreateChangeSet",
                    "cloudformation:ListStacks",
                    "cloudformation:UpdateStack",
                    "cloudformation:DescribeStacks",
                    "cloudformation:DescribeStackResource",
                    "cloudformation:DescribeStackEvents",
                    "cloudformation:ValidateTemplate",
                    "cloudformation:DescribeChangeSet",
                    "cloudformation:ExecuteChangeSet",
                    "cloudformation:GetTemplateSummary"
                ],
                "Resource": [
                    "*"
                ]
            }
        ]
    }
    

    【讨论】:

    • 如果你提到有什么区别会更有帮助。只有 GetTemplateSummary?
    • 真的很有用。谢谢
    【解决方案5】:

    如果您有多个 AWS 配置文件,请尝试明确

    export AWS_ACCESS_KEY_ID=<value>
    export AWS_SECRET_ACCESS_KEY=<value>
    

    尝试之前

    serverless deploy
    

    【讨论】:

    • 这是最快的解决方案!
    【解决方案6】:

    这两个帮助我越过了这条线......

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

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "cloudformation:ListStacks",
                    "cloudformation:DescribeStackEvents",
                    "cloudformation:CreateStack",
                    "cloudformation:UpdateStack",
                    "cloudformation:DescribeStackResource",
                    "cloudformation:CreateChangeSet",
                    "cloudformation:DescribeChangeSet",
                    "cloudformation:ExecuteChangeSet",
                    "cloudformation:ValidateTemplate"
                ],
                "Resource": "*"
            }
        ]
    }
    

    【讨论】:

      【解决方案7】:

      创建以下策略:

      1. 点击策略 -> 创建策略
      2. 在选择服务下 - 键入 EKS 并选择“EKS”
      3. 在操作下:选择“所有 EKS 操作”
      4. 在资源下:选择“所有资源”或添加 ARN
      5. 点击审核政策
      6. 键入策略的名称并创建策略。

      现在,将此策略与用户帐户相关联。 这应该可以解决问题并且您应该能够创建堆栈。

      【讨论】:

        【解决方案8】:

        随着 AWS 的最新更新,以下内联策略也将起作用。

        {
           "Version": "2012-10-17",
           "Statement": [
               {
                    "Sid": "VisualEditor0",
                    "Effect": "Allow",
                    "Action": [
                        "cloudformation:DeleteStack"
                    ],
                    "Resource": "*"
                }
            ]
        }
        

        【讨论】:

          【解决方案9】:

          我通过在 AWS 控制台中向用户添加权限来解决此问题:

          1. 转到 AWS 控制台
          2. 查找您正在使用其凭证的用户 IAM > 访问管理 > 用户
          3. 权限 >“添加权限”>“直接附加现有策略”
          4. 搜索并选择“AWSCloudFormationFullAccess”

          【讨论】:

            【解决方案10】:

            仅供其他人参考,以防他/她正在搜索问题并到达此处:

            确保您删除了该 IAM 用户的权限边界。

            如果您发现您已向 IAM 用户授予 cloudformation 完全访问权限,但仍然收到声明 User is not authorized to perform: cloudformation:CreateStack 的相同错误,则它被权限边界拒绝。

            【讨论】:

            【解决方案11】:

            根据this comment,我启用了 MFA,并且必须使用 MFA 代码获取临时凭证才能使 AWS SAM 正常工作

            【讨论】:

              【解决方案12】:

              (至少现在)有一个部分 in the docs

              With a gist 显示他们推荐的 JSON 政策。

              【讨论】:

                【解决方案13】:

                向您创建的用户授予“管理员”访问权限

                【讨论】:

                • 虽然此答案可能在一定程度上有所帮助,但您应该详细说明如何实施您的解决方案,以及它对其他答案的添加。
                猜你喜欢
                • 2018-11-07
                • 2021-02-26
                • 1970-01-01
                • 2016-09-26
                • 2016-02-16
                • 2016-04-19
                • 2019-01-22
                • 2021-02-08
                • 1970-01-01
                相关资源
                最近更新 更多