如何在 TypeScript 中使用 CDK 成功部署嵌套 AWS Step Functions?

问题描述 投票:0回答:1

我目前正在使用 AWS CDK(最新版本的 aws-cdk-lib)来部署嵌套 Step Functions,其中外部状态机触发内部状态机。但是,我在当前设置中遇到了 IAM 权限错误,并且无法找到特定于此场景的示例或文档。

这是我一直在尝试的代码片段:

import * as sfn from 'aws-cdk-lib/aws-stepfunctions';

// create outerStateMachine from definition
const outerStateMachine = new sfn.StateMachine(this, 'OuterStateMachine', {
      definitionBody: sfn.DefinitionBody.fromFile('location_of_osm_def_json'),
}); 

// innerStateMachine already exists, grant execute permission to outerStateMachine
innerStateMachine.grantExecution(
    outerStateMachine.role,
    'states:StartExecution',
    'states:StopExecution'
);

错误根据我所做的修改而有所不同,但通常与权限不足有关。

有人在 TypeScript 中使用 CDK 成功实现了嵌套 AWS Step Functions 吗?如果有任何有关如何为此类部署正确配置 IAM 角色(使用 cdk)的工作代码示例或建议,我将不胜感激。

aws-cdk aws-step-functions
1个回答
0
投票

您可以尝试使用简单的

grant
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.StateMachine.html#grantwbrexecutionidentity-actions) 。 如果我正确理解文档,
grantExecution
会授予您对执行的操作,而不是对状态机的操作。

© www.soinside.com 2019 - 2024. All rights reserved.