LoginSignup
0
0

More than 5 years have passed since last update.

AWS Powershell TagSpecificationパラメータの書き方

Last updated at Posted at 2019-03-07

はじめに

公式ドキュメントにはTagSpecificationの書き方が載っていなくて困った。
ググっても出てこないし。

せっかく同時にタグ付与できるのだから作成後にNew-EC2Tagで付けるのはちょっとイケてないですよね

以下サンプル

書き方はどのコマンドレットでも同じで、
Tagを付けるコマンドレットによってResourceTypeを適宜変更する必要があります。

複数行版を併記しているのは「こういう構造になっているのですよ」ということをわかってもらい、
ワンライナーを書き換えたけどエラー出た。という悲しい事件を減らすためです。

New-EC2VolumeでTagSpecification

複数行版

$TagSpecification = @{
  ResourceType = "Volume";
  Tags         = @(
    @{Key = "hogehoge"; value = "foo"},
    @{Key = "piyopiyo"; Value = "bar"}
  );
}
New-EC2Volume -SnapshotId "snap-xxxxxxxxxxxxxxxxx" -AvailabilityZone "us-east-1f" -TagSpecification $TagSpecification

ワンライナー

New-EC2Volume -SnapshotId "snap-xxxxxxxxxxxxxxxxx" -AvailabilityZone "us-east-1f" -TagSpecification @{ResourceType = "Volume"; Tags = @(@{Key = "hogehoge"; value = "foo"}, @{Key = "piyopiyo"; Value = "bar"}); }

New-EC2SnapshotでTagSpecification

複数行版

$TagSpecification = @{
  ResourceType = "Snapshot";
  Tags         = @(
    @{Key = "hogehoge"; value = "foo"},
    @{Key = "piyopiyo"; Value = "bar"}
  );
}
New-EC2Snapshot -VolumeId "vol-xxxxxxxxxxxxxxxxxx" -TagSpecification $TagSpecification

ワンライナー

New-EC2Snapshot -VolumeId "vol-xxxxxxxxxxxxxxxxxx" -TagSpecification @{ResourceType = "Snapshot"; Tags = @(@{Key = "hogehoge"; value = "foo"}, @{Key = "piyopiyo"; Value = "bar"}); }

使用可能なResourceTypeの一覧

このFields - Nameです。
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html?page=EC2/TEC2TagSpecification.html&tocid=Amazon_EC2_Model_TagSpecification

0
0
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
0
0