【问题标题】:botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the CreateStateMachine operationbotocore.exceptions.ClientError:调用 CreateStateMachine 操作时发生错误 (AccessDeniedException)
【发布时间】:2020-01-19 23:20:36
【问题描述】:

当我尝试根据我的状态机定义创建状态机时出现以下错误:

botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the CreateStateMachine operation: 'role' is not authorized to create managed-rule.

创建代码:

state_machine = sfn_client.create_state_machine(
    name = 'state-machine',
    definition = state_machine_def,
    roleArn = SFN_ROLE,
)

我使用的 IAM 角色包含所有必要的权限,如 here 所述。它需要什么样的托管规则才能拥有创建权限?

【问题讨论】:

  • 那么您是否对角色应用了策略?您可以分享附加到该角色的 IAM 策略吗?
  • 我的角色附加了以下策略:AWSLambdaRole CloudWatchFullAccess + 允许完全 AWS 批处理/ECR 访问以及传递角色的自定义策略

标签: amazon-web-services boto3 aws-step-functions


【解决方案1】:

您很可能错过了向 IAM 角色添加正确的策略。这是来自official documentation 的政策,允许您创建、列出状态机。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "states:ListStateMachines",
        "states:ListActivities",
        "states:CreateStateMachine",
        "states:CreateActivity"
      ],
      "Resource": [ 
        "arn:aws:states:*:*:*" 
      ]
    },
    {
      "Effect": "Allow",
      "Action": [ 
        "iam:PassRole"
      ],
      "Resource": [
        "arn:aws:iam:::role/my-execution-role"
      ]
    }
  ]

【讨论】:

    【解决方案2】:

    原因是 SFN_ROLE 附加的 CloudWatchFullAccess 策略没有足够的权限让 Step Functions 工作流将事件发布到 CloudWatch。一旦我用 CloudWatchEventsFullAccess 替换它,一切正常。

    【讨论】:

    • 看起来 CloudWatchEventsFullAccess 为 CFN_ROLE 提供了对 CWE "Action": "events:*", "Resource": "*" 的完全访问权限。您是否能够缩小所需的确切权限范围?
    【解决方案3】:

    事实证明,添加 CloudWatchEventsFullAccess 适用于 stepfunctions

    【讨论】:

      【解决方案4】:

      问题是这样的

      {
              "Effect": "Allow",
              "Action": [
                  "events:PutTargets",
                  "events:PutRule",
                  "events:DescribeRule"
              ],
              "Resource": [
                 "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule"
              ]
          }
      

      根据AWS Step Function nested workflow Execution,需要添加step function角色监听和创建事件的具体规则StepFunctionsGetEventsForStepFunctionsExecutionRule就是你要找的规则

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-08
        • 1970-01-01
        • 2017-12-07
        • 2018-12-09
        • 1970-01-01
        • 2020-09-14
        • 2019-07-14
        • 2021-05-02
        相关资源
        最近更新 更多