【问题标题】:How to get an AWS ServiceLinkedRole ARN in CloudFormation如何在 CloudFormation 中获取 AWS ServiceLinkedRole ARN
【发布时间】:2020-03-13 23:01:10
【问题描述】:

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

  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: ??

我尝试过以下格式:

RoleARN: !Ref "AWSServiceLinkedRoleForConfig"

传递的角色 'AWSServiceRoleForConfig' 无效。 (服务: 亚马逊配置;状态码:400;错误代码:InvalidRoleException; )

RoleARN: !Ref "AWSServiceLinkedRoleForConfig.Arn"

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

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

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

【问题讨论】:

    标签: amazon-cloudformation


    【解决方案1】:

    在您的 CloudFormation Resources 中,创建角色并在 Properties 部分中,给它一个 RoleName

      MyRoleForCodePipeline:
        Type: AWS::IAM::Role
        Properties:
          RoleName: myrolename
          ...
    

    然后创建管道并使用您的账户 ID(例如 123456780)和上面的角色名称手动构建 ARN:

      MyCodePipeline:
        Type:  AWS::CodePipeline::Pipeline
        Properties:
          Name: mycodepipelinename
          RoleArn: 'arn:aws:iam::123456780:role/myrolename'
          ...
    
    

    【讨论】:

      【解决方案2】:

      我刚刚得到 AWS 的答复:

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

      可用的解决方法:

      角色ARN: !加入 - '' - - 'arn:aws:iam::' - !Ref 'AWS::AccountId' - ':role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig'

      【讨论】:

        猜你喜欢
        • 2022-08-11
        • 1970-01-01
        • 2018-11-13
        • 1970-01-01
        • 2021-02-10
        • 2020-04-09
        • 2020-08-06
        • 2020-10-03
        • 1970-01-01
        相关资源
        最近更新 更多