我在 SAM/CloudFormation 模板中创建了一个 Step Function(父函数),除其他外,它还调用另一个 Step Function(子函数)。我正在按照有关从父级调用子级的说明,使用 service integration pattern 。但在通过 CLI 部署时,我遇到了无法解决的与 IAM 相关的(我认为)错误。 (错误出现在 CLI 输出中,因此它实际上从未进入 AWS。之前有大量部署,因此 changeset
只是尝试通过此部署修改 Step Function .)
'arn:aws:iam::{Account-Number}:role/{Parent-Step-Function-Role-Name}' is not authorized to create managed-rule. (Service: AWSStepFunctions; Status Code: 400; Error Code: AccessDeniedException; Request ID: {Long-Id-Number})
为了获得我想要的同步行为(父级调用子级,等待子级执行完成,然后进入下一个状态),我使用建议(来自上面的服务集成模式链接)创建一个任务(在我的SAM 模板)如下所示:
...More States...
"Call Child State": {
"Type": "Task",
"Next": "The Next State",
"Resource": "arn:aws:states:::states:startExecution.sync",
"Parameters": {
"Input": {
"comment": "Hello World!"
},
"StateMachineArn": "${ChildStepFunction}",
"Name": "ChildExecutionFromParent"
}
},
...More States...
我为 Parent 定义了 IAM 角色,如下所示,确保它仅具有 Parent 中 Lambda 函数的 Lambda 执行权限,并且更适用于该问题,具有 StartExecution
child 。我按照下面链接中的说明进行操作,其中指出 StartExecution 是使用服务集成模式时所需的唯一权限。
https://docs.aws.amazon.com/step-functions/latest/dg/stepfunctions-iam.html
ParentStepFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Principal:
Service:
- !Sub states.${AWS::Region}.amazonaws.com
Action: sts:AssumeRole
Policies:
-
PolicyName: ChildStepFunctionExecution
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action: states:StartExecution
Resource: !Ref ChildStepFunction
-
Effect: Allow
Action: lambda:InvokeFunction
Resource:
- !GetAtt Function1.Arn
...
- !GetAtt FunctionX.Arn
我尝试将上述状态替换为简单的 Pass
状态,以确保 Step Function 中没有其他错误阻止部署,并且部署正常。所以我知道这与那个州有关。 (还值得注意的是,在使用 Pass
状态进行部署进行测试时,我保留了上面定义的角色,因此,我再次知道这不是导致此问题的策略语法错误。显然,这与可能有错误或缺失政策不同。)
最佳答案
[根据 @Matt 的帖子和 @Joe.CK 的评论于 2020 年 5 月 22 日更新,以将范围缩小到所需的特定资源。]
这个 Stack Overflow 问题为我指明了正确的方向。 botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the CreateStateMachine operation
该问题似乎源于 CloudWatch,我通过将以下语句添加到我的 IAM 策略中解决了这个问题。
- Effect: Allow
Action:
- events:PutTargets
- events:PutRule
- events:DescribeRule
Resource:
- !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule
AWS Step Functions 示例项目“在工作流程中启动工作流程”包含类似的内容,但仅限于它调用的单个 Lambda 函数。
关于amazon-web-services - Step 函数中嵌套 Step 函数 : Unknown Error: "...not authorized to create managed-rule",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60612853/