CloudFormation模板中属性Id的值必须为String - Error类型



我使用下面的cloudformation模板为NLB创建一个目标组。在执行cloudformation模板时,我得到了错误"属性Id的值必须是字符串类型"因为Targets: - Id: !Ref InstanceID。我选择了AWS::EC2::Instance::Id作为列表,因为希望在此目标组中关联多个实例。请任何人帮助我了解到底是哪里出了问题。

Parameters:
InstanceID:
Description: Please Select the Instance IDs
Type: List<AWS::EC2::Instance::Id>
Description: Select Instance ID to associate it with the Target Group
VPC:
Description: The VPC to deploy to the target group
Type: AWS::EC2::VPC::Id
ConstraintDescription: Select VPC ID for the Target Group
Resources:
EC2TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:                                                     
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: TCP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 3        
Name: NLBTargetGroupForEndpointService
Port: 22
Protocol: TCP        
TargetType: instance
Targets:
- Id: !Ref InstanceID
UnhealthyThresholdCount: 3
VpcId: !Ref VPC
Tags:
- Key: Name
Value: EC2TargetGroup
- Key: Port
Value: 22
- Key: Protocol
Value: TCP

你不能这样做,因为目标是一个对象https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-targetgroup-targetdescription.html。

如果你想动态填充目标,你必须开发自己的cloudformation宏或自定义资源。

!Ref InstanceID,我认为它得到多值字符串而不是一个InstanceId。您可以尝试将InstanceId参数设置为字符串类型。

参考https://aws.amazon.com/premiumsupport/knowledge-center/multiple-values-list-parameter-cli/说明安全组参考

相关内容

最新更新