Amazon cloudformation AWS云信息Fn::导入值不';我不喜欢!参加

Amazon cloudformation AWS云信息Fn::导入值不';我不喜欢!参加,amazon-cloudformation,Amazon Cloudformation,我的CloudFormation模板中有以下资源,它正在尝试创建侦听器规则。想法是,基于传入的EnvironmentType和AWS区域,我想从导出它的相应CloudFormation堆栈导入侦听器ARN Parameters: EnvironmentType: Type: String Default: "sandbox" ECSClusterStackNameParameter: Type: String Default: &quo

我的CloudFormation模板中有以下资源,它正在尝试创建侦听器规则。想法是,基于传入的EnvironmentType和AWS区域,我想从导出它的相应CloudFormation堆栈导入侦听器ARN

Parameters:
  EnvironmentType:
    Type: String
    Default: "sandbox"
  ECSClusterStackNameParameter:
    Type: String
    Default: "ECS-US-Sandbox"

Mappings:
  production:
    us-east-1:
      stackWithAlbListenerInfo: "ECS-US-Prod"
    eu-north-1:
      stackWithAlbListenerInfo: "ECS-EU-Prod"
  staging:
    us-east-1:
      stackWithAlbListenerInfo: "ECS-US-Staging"
    eu-north-1:
      stackWithAlbListenerInfo: ""
  sandbox:
    us-east-1:
      stackWithAlbListenerInfo: "ECS-US-Sandbox"
    eu-north-1:
      stackWithAlbListenerInfo: ""

Conditions:
  StackExists:
    !Not [ !Equals [ !FindInMap [ !Ref EnvironmentType, !Ref "AWS::Region", stackWithAlbListenerInfo ], ""] ]

Resources:
  AlbListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Condition: UseListenerRule
    Properties:
      ListenerArn:
        !If
          - StackExists
          -
            - Fn::ImportValue:
                !Join
                  - "-"
                  - - !FindInMap [ !Ref EnvironmentType, !Ref "AWS::Region", stackWithAlbListenerInfo ]
                    - "ListenerArn"
          - Fn::ImportValue:
              - !Sub "${ECSClusterStackNameParameter}-ListenerArn"
但是,由于此错误,它无法验证,并且第一个
Fn::ImportValue:
似乎不喜欢
!加入
。但是
!Join
返回连接的字符串是否正确?我错过了什么

ERROR: Service: marcom-stats-service, cfnUpdate error: com.amazonaws.services.cloudformation.model.AmazonCloudFormationException: Template error: the attribute in Fn::ImportValue must be a string or a function that returns a string (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 2678552e-cf6c-46e1-b640-a7c07de385c2; Proxy: null)
更新:

虽然Robert Kossendey的回答修复了我的错误,但我原来的模板是错误的。这就是我真正想做的。我希望它能帮助别人

  AlbListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Condition: UseListenerRule
    Properties:
      ListenerArn:
        Fn::ImportValue: !Sub
          - ${StackName}-ListenerArn
          - { StackName: !If [ StackExists, !FindInMap [ !Ref EnvironmentType, !Ref "AWS::Region", stackWithAlbListenerInfo ], !Ref ECSClusterStackNameParameter ] }

现在我看到了,我想。在第二次导入时,您需要删除
前面的破折号!子

- Fn::ImportValue:
  !Sub "${ECSClusterStackNameParameter}-ListenerArn"

您能否删除Fn:ImportValue前面的破折号?我认为If函数不希望在那里出现嵌套列表,所以可能这也会导致问题。谢谢,我试过了,得到了相同的错误。谢谢,就是这样。我看错地方了。没问题,如果这对你有帮助的话,请投上一票!