【发布时间】:2026-01-17 13:05:02
【问题描述】:
如何将参数(CommaDelimitedList 或 String 类型)传递给单个 TargetGroup 的 Target:-Id: 属性并让它遍历并分配列表中的每个实例?
目前,我可以将一个或多个 Target-Servers 传递给 Target-Group,方法是将每个 Target 作为它自己的 -Id: 属性。下面的代码块 #1 可以工作,我怎样才能使代码块 #2 工作?
MyTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
#[All the Target Group properties that aren't in question]
Targets:
- Id: "i-000AWS001"
Or
- Id: !Ref WebServer1
#Two Files:
# resource.yml - Cloudformation yaml file
# conf_resource.json - json paramaters file
# Parameter value in the Conf file
{
"WebServers":"i-000AWS001,i-000AWS002,i-000AWS003,i-000AWS004,i-000AWS005"
}
# ..
#Target Group Resource
Parameters:
WebServers:
Type: CommaDelimitedList
Default: "@@@WebServers@@@"
Description: " A comma delimited list of AWS Ec2 Webserver instances"
Resources:
MyAlb:
ALBProperties:
#[All the Application Load balancer properties that aren't in question]
MyTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
#[All the Target Group properties that aren't in question]
Targets:
- Id: !Split[ "," , !Ref WebServers ]
#Also tried - Id: !Ref [ !Split[ "," , !Ref WebServers ] ]
AWS TargetGroup 文档: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-targetgroup.html#cfn-elasticloadbalancingv2-targetgroup-targets
【问题讨论】:
标签: amazon-web-services yaml amazon-cloudformation