如何在 CloudFormation 中获取 AWS ServiceLinkedRole ARN

man*_*107 2 aws-cloudformation

我正在尝试使用 ServiceLinkedRole for Config 为 AWS Config 服务创建 CloudFormation 堆栈,但是我不知道如何在同一 CloudFormation 模板中引用创建的 AWS Config 角色的 ARN,这是配置片段:

  AWSServiceLinkedRoleForConfig:
    Type: 'AWS::IAM::ServiceLinkedRole'
    Properties:
      AWSServiceName: config.amazonaws.com
      Description: AWS Config Service Linked role
  ConfigRecorder: 
    Type: AWS::Config::ConfigurationRecorder
    Properties: 
      Name: AWSConfigForTest
      RecordingGroup: 
        ResourceTypes: 
          - "AWS::EC2::SecurityGroup"
      RoleARN: ??
Run Code Online (Sandbox Code Playgroud)

我试过以下格式:

RoleARN: !Ref "AWSServiceLinkedRoleForConfig"
Run Code Online (Sandbox Code Playgroud)

通过“AWSServiceRoleForConfig”的角色 arn 无效。(服务:AmazonConfig;状态代码:400;错误代码:InvalidRoleException;)

RoleARN: !Ref "AWSServiceLinkedRoleForConfig.Arn"
Run Code Online (Sandbox Code Playgroud)

模板格式错误:模板资源块中未解析的资源依赖关系 [AWSServiceLinkedRoleForConfig.Arn]

根据以下备忘单,ServiceLinkedRole 资源没有输出 ARN:https : //theburningmonk.com/cloudformation-ref-and-getatt-cheatsheet/

如果是这种情况,我如何在 CloudFormation 模板文件中引用此角色的 ARN?

man*_*107 6

我刚刚从 AWS 得到了一个答案:

无法直接引用在 CloudFormation 中创建的服务相关角色的 ARN

可用的解决方法:

RoleARN: !Join - '' - - 'arn:aws:iam::' - !Ref 'AWS::AccountId' - ':role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig'