【问题标题】:AWS IAM Cloudformation YAML template errror: 'null' values are not allowedAWS IAM Cloudformation YAML 模板错误:不允许使用“空”值
【发布时间】:2018-08-24 20:32:15
【问题描述】:

我正在为授予跨账户只读访问权限的 IAM 角色开发 Cloudformation 模板。它也使用托管策略进行只读访问。到目前为止,我已经解决了几个错误,但现在我在尝试验证模板时收到“模板中不允许使用‘null’值”错误。我认为这是一个空间或语法问题,但我不能确定,因为这是我第一次从头开始创建 cloudformation 模板并使用 YAML。

AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation template IAM Role for New Relic to have read access to AWS account
Resources:
  NewRelicInfrastructure-IntegrationsRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
      Version: '2012-10-17'
      Statement:
        Effect: Allow
        Principal:
          AWS: 11111111
        Action: sts:AssumeRole
        Condition:
          StringEquals:
          sts:ExternalId: '11111'
  Path: '/'
  ManagedPolicyArns: arn:aws:iam::aws:policy/ReadOnlyAccess
  RoleName: NewRelicInfrastructure-Integrations2

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-iam


    【解决方案1】:

    问题在于AssumeRolePolicyDocument:。它是必需的,但您将其留空。您还有一个缩进问题,其中PathManagedPolicyArnsRoleNameResources 下而不是Properties

    试试:

    AWSTemplateFormatVersion: '2010-09-09'
    Description: AWS CloudFormation template IAM Role for New Relic to have read access to AWS account
    Resources:
      NewRelicInfrastructure-IntegrationsRole:
        Type: AWS::IAM::Role
        Properties:
          AssumeRolePolicyDocument:
            Version: '2012-10-17'
            Statement:
              Effect: Allow
              Principal:
                AWS: 11111111
              Action: sts:AssumeRole
              Condition:
                StringEquals:
                sts:ExternalId: '11111'
          Path: '/'
          ManagedPolicyArns: arn:aws:iam::aws:policy/ReadOnlyAccess
          RoleName: NewRelicInfrastructure-Integrations2
    

    【讨论】:

    • 我知道这已经过时了,而且已经过期了,但是很好的答案。可惜原贴忽略了您,并使用了他自己的丑陋但可行的解决方案。你应得的荣誉:)
    【解决方案2】:

    缩进已修复,它在 AssumeRolePolicyDocument 中指定了某些内容,但 YAML 语法不正确,这有效:

    AWSTemplateFormatVersion: '2010-09-09'
    Description: AWS CloudFormation template IAM Role for New Relic to have read access to AWS account
    Resources:
      NewRelicInfrastructureIntegrationsRole: 
        Type: AWS::IAM::Role
        Properties:
          Path: '/managed/'
          ManagedPolicyArns: 
            - 'arn:aws:iam::aws:policy/ReadOnlyAccess'
          AssumeRolePolicyDocument:
            Version: '2012-10-17'
            Statement:
            - 
              Action: sts:AssumeRole  
              Effect: Allow
              Principal:
                AWS: 1111111111111
              Condition:
                StringEquals:
                  sts:ExternalId: '11111'
          RoleName: NewRelicInfrastructureIntegrationsRole
    

    【讨论】:

    • 如果以后有人来寻找解决同类问题的方法,请参阅the answer belowkichik。在 为什么 存在问题的解释中更加清楚,并且该解决方案不需要此答案在“语句:”之后具有的丑陋且不必要的带连字符的空白行。
    【解决方案3】:

    在线使用 YAML 解释器向您展示您可能在 yaml 文件中获得空值的位置。很难发现它们,因为错误的缩进会导致 null 值 - yaml 解释器会在 json 中显示您获取该值的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-05
      • 2023-04-02
      • 2017-06-18
      • 2017-06-25
      • 1970-01-01
      • 2020-10-05
      • 2021-04-27
      • 2022-01-16
      相关资源
      最近更新 更多