botocore.exceptions.ClientError:调用 CreateStateMachine 操作时发生错误 (AccessDeniedException)

Ale*_*ich 6 amazon-web-services boto3 aws-step-functions

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

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

创建代码:

state_machine = sfn_client.create_state_machine(
    name = 'state-machine',
    definition = state_machine_def,
    roleArn = SFN_ROLE,
)
Run Code Online (Sandbox Code Playgroud)

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

Ale*_*ich 7

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


Joe*_*.CK 5

问题是这样的

{
        "Effect": "Allow",
        "Action": [
            "events:PutTargets",
            "events:PutRule",
            "events:DescribeRule"
        ],
        "Resource": [
           "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule"
        ]
    }
Run Code Online (Sandbox Code Playgroud)

根据AWS Step Function嵌套工作流执行,您需要添加步骤函数角色的特定规则来监听和创建事件,StepFunctionsGetEventsForStepFunctionsExecutionRule这就是您正在寻找的规则


Jun*_*san 1

您很可能错过了向 IAM 角色添加正确的策略。这是官方文档中的一项策略,允许您创建、列出状态机。

{
  "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"
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)