使用AWS CLI创建带双标签的EC2 Auto Scaling Group时标签异常问题
Hey there! I can spot exactly why only your last tag is sticking when creating the Auto Scaling Group (ASG)—let's get this sorted out quickly.
The issue lies in how you formatted the --tags parameter in your AWS CLI command. When you cram multiple Key=/Value= pairs into a single comma-separated string, AWS CLI interprets all those pairs as part of one single tag, with later keys overwriting earlier ones. That's why only Tag_2 ends up on your ASG.
Here are two correct ways to add multiple tags:
1. Use separate --tags parameters for each tag
This is the most readable approach, especially if you have more than a couple of tags:
aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name usr \ --launch-configuration-name TEST \ --min-size 0 \ --max-size 20 \ --vpc-zone-identifier subnet-xxxx \ --tags ResourceId=usr,ResourceType=auto-scaling-group,Key=tag_1,Value=value_1,PropagateAtLaunch=true \ --tags ResourceId=usr,ResourceType=auto-scaling-group,Key=Tag_2,Value=value_2,PropagateAtLaunch=true
2. Space-separate complete tag entries in one --tags parameter
If you prefer using a single --tags flag, define each tag as its own comma-separated block, separated by spaces:
aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name usr \ --launch-configuration-name TEST \ --min-size 0 \ --max-size 20 \ --vpc-zone-identifier subnet-xxxx \ --tags ResourceId=usr,ResourceType=auto-scaling-group,Key=tag_1,Value=value_1,PropagateAtLaunch=true ResourceId=usr,ResourceType=auto-scaling-group,Key=Tag_2,Value=value_2,PropagateAtLaunch=true
Either method will ensure both tags are applied properly. The key takeaway is that each tag needs to be a distinct entry—either via separate flags or space-separated blocks—rather than jamming all Key/Value pairs into one comma list.
内容的提问来源于stack exchange,提问作者Goran Jamicic

