gpt4 book ai didi

aws-cloudformation - AWS CloudFormation Fn::ImportValue 不喜欢 !Join?

转载 作者:行者123 更新时间:2023-12-03 07:14:09 26 4
gpt4 key购买 nike

我的 CloudFormation 模板中有以下资源正在尝试创建监听器规则。我的想法是,根据传入的 EnvironmentType 和 AWS 区域,我想从导出监听器 ARN 的相应 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。但是 !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 Kossenney 的回答纠正了我的错误,但我原来的模板是错误的。这确实是我想做的。我希望它对某人有帮助。

  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 ] }

最佳答案

现在我想我明白了。在第二次导入时,您需要删除 !Sub 前面的破折号:

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

关于aws-cloudformation - AWS CloudFormation Fn::ImportValue 不喜欢 !Join?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67640404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com