0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

自分のタグを取得するスクリプト<EC2編>

Posted at

CodeDeployは、CodeBuildの様に環境変数がPipelineから指定できないので、AppSpecFileの中でデプロイ内容をタグの値に応じて制御したいような場合に有効活用できるかも知れません

  1. EC2インスタンス自身のメタ情報のインスタンスIDを取得する
  2. インスタンスIDを指定して、特定のタグの値を取得する

例えば、「TagNoNamae」の値を取得したい場合、以下の操作で取得できる

コマンド例
AWS_REGION=ap-northeast-1
MYINSTANCEID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
VALUE=`aws ec2 describe-tags --region $AWS_REGION --filter "{\"Name\":\"resource-id\",\"Values\": [\"$MYINSTANCEID\"]}" --query 'Tags[?Key==\`TagNoNamae\`][Value]' --output text`
echo $VALUE

※「TagNoNamae」の部分を変更することで他のタグの値が取得できます

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?