LoginSignup
2
2

More than 5 years have passed since last update.

[AWS] ELBとEC2の tag:Name の仕様の違いについて

Last updated at Posted at 2018-01-12

細かい点ですが、EC2とELBの所謂「Nameタグ」の仕様に違いがあったのでまとめておきます。

EC2の場合

コンソールでEC2を確認すると、一覧と「タグ」タブ内に2つ"Name"が確認できます。EC2では、この2つは同じものです。

image.png

これは実体としてはタグで、describe-instancesコマンドで確認できます。

$ aws ec2 describe-instances --region eu-west-3 | jq -r '.Reservations[] .Instances[] .Tags[]'
{
  "Value": "bastion-ec2",
  "Key": "Name"
}

更新したい場合は、create-tagsコマンドで(少々違和感がありますが)上書きできます。

$ aws ec2 create-tags --region eu-west-3 --resources i-02axxxxxxxxxxxxx --tags Key=Name,Value=name-update-test

コンソールでは両方更新されることが確認できます。

image.png

ELBの場合

コンソールでELBを確認すると、一覧の方に"名前"が、「タグ」タブの方に"Name"が表示されています。EC2と似た表示ですが、ELBではこれらは別物です。

image.png

"名前"の方はロードバランサ名(LoadBalancerName)でdescribe-load-balancersコマンドで確認できます。"Name"の方がタグで、describe-tagsコマンドで確認できます。

$ aws elb describe-load-balancers --region eu-west-3 | jq -r '.LoadBalancerDescriptions[] .LoadBalancerName'
internal-elb
$ aws elb describe-tags --region eu-west-3 --load-balancer-names internal-elb
{
    "TagDescriptions": [
        {
            "Tags": [
                {
                    "Value": "this-is-name-tag",
                    "Key": "Name"
                }
            ],
            "LoadBalancerName": "internal-elb"
        }
    ]
}

ロードバランサ名(LoadBalancerName)の方は、作成後には更新できません。タグの方はEC2と同様にadd-tagsコマンドで上書きできます。

$ aws elb add-tags --region eu-west-3 --load-balancer-names internal-elb --tags Key=Name,Value=tag-update-test
$ aws elb describe-tags --region eu-west-3 --load-balancer-names internal-elb
{
    "TagDescriptions": [
        {
            "Tags": [
                {
                    "Value": "tag-update-test",
                    "Key": "Name"
                }
            ],
            "LoadBalancerName": "internal-elb"
        }
    ]
}

コンソールでもタグの方だけ更新されたことが確認できます。

image.png

ALBまたはNLBの場合

ALB(Application Load Balancer)またはNLB(Network Load Balancer)の場合も同様の動作となります。awscliはelbv2コマンドで確認できます。

名前とタグの確認:

$ aws elbv2 describe-load-balancers --region ap-northeast-1 | jq -r '.LoadBalancers[] .LoadBalancerName'
internal-elb
$ aws elbv2 describe-tags --region ap-northeast-1 --resource-arns arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/net/internal-elb/xxxxxxxxxx
{
    "TagDescriptions": [
        {
            "ResourceArn": "arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/net/internal-elb/xxxxxxxxxx",
            "Tags": [
                {
                    "Value": "this-is-name-tag",
                    "Key": "Name"
                }
            ]
        }
    ]
}

タグの変更:

$ aws elbv2 add-tags --region ap-northeast-1 --tags Key=Name,Value=tag-update-test --resource-arns arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/net/internal-elb/xxxxxxxxxx
$ aws elbv2 describe-tags --region ap-northeast-1 --resource-arns arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/net/internal-elb/xxxxxxxxxx
{
    "TagDescriptions": [
        {
            "ResourceArn": "arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/net/internal-elb/xxxxxxxxxx",
            "Tags": [
                {
                    "Value": "tag-update-test",
                    "Key": "Name"
                }
            ]
        }
    ]
}

まとめ

EC2の場合は特に意識せず「Nameタグ」を使っていましたが、ELBの場合は名前(LoadBalancerName)とタグ(tag:Name)が別々に設定できるので混同しないよう注意が必要です。違う値を設定した場合はどちらを意図しているのかきちんと確認するようにしましょう。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2