You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS CLI创建带双标签的EC2 Auto Scaling Group时标签异常问题

Fixing Missing Tags in Your AWS Auto Scaling Group Creation Command

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:10:28