我有一个类似的Cloudformation堆栈,
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyFavoriteActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name: "my-special-name"
ActivityAccessRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
AWS:
Fn::Sub: "arn:aws:iam::${AWS::AccountId}:user/my-special-user"
Action:
- sts:AssumeRole
Policies:
- PolicyName: "Activity_Role_Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:GetActivityTask
Resource: { Ref: "MyFavoriteActivity" }
使用Boto3,我尝试使用ActivityAccessRole
中的键调用get_activity_task
,
sfn_client = boto3.client('stepfunctions', **assumed_role_keys)
task = sfn_client.get_activity_task(
activityArn='arn:aws:states:us-west-2:012345678910:activity:My-favorite-activity',
workerName='my-worker'
)
但是我收到了错误,
An error occurred (AccessDeniedException) when calling the GetActivityTask operation:
User: arn:aws:sts::012345678910:assumed-role/some-prefix-ActivityAccessRole-some-hash/AssumeRoleSession1
is not authorized to perform: states:GetActivityTask on resource: arn:aws:states::012345678910:role/arn:aws:states:us-west-2:012345678910:activity:My-favorite-activity
我看到的问题是我从未创建arn:aws:states::012345678910:role/arn:aws:states:us-west-2:012345678910:activity:My-favorite-activity
(注意前缀)!
如何修复我的CF模板以提供适当的权限?
答案 0 :(得分:1)
问题非常愚蠢(或天才和记录不完整)。我需要改变我的角色,
ActivityAccessRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
AWS:
Fn::Sub: "arn:aws:iam::${AWS::AccountId}:user/frp-api-user"
Action:
- sts:AssumeRole
Policies:
- PolicyName: "Activity_Role_Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:GetActivityTask
Resource:
- Fn::Sub: "arn:aws:states::${AWS::AccountId}:role/${MyFavoriteActivity}"
- { Ref: "MyFavoriteActivity" }
你应该注意最后两行。由于某种原因需要添加两种资源。真实的,真空的。