この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
こんにちは、岩城です。
インスタンスメタデータのアップデートを紹介します。
インスタンスメタデータは実行中のインスタンスから以下の URI にアクセスすることで様々なデータを取得することができます。
http://169.254.169.254/latest/meta-data/
取得できるデータはカテゴリ分けされています。
$ curl http://169.254.169.254/latest/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hibernation/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
reservation-id
security-groups
今回のアップデートにより、placement
カテゴリに以下 5 つのフィールドが追加されました。
- placement/availability-zone-id
- placement/group-name
- placement/host-id
- placement/partition-number
- placement/region
実際に URI を叩いて返ってくる情報を確かめてみたいと思います。
やってみた
placement/availability-zone-id
ap-northeast-1a
のような名前ではなくavailability-zone-id
を返します。
$ curl http://169.254.169.254/latest/meta-data/placement/availability-zone-id
apne1-az4
placement/group-name
プレイスメントグループは、同じグループ内のインスタンス間の通信を高速化させるものです。 インスタンス起動時にプレイスメントグループを指定している場合、プレイスメントグループの名前を返します。
$ curl http://169.254.169.254/latest/meta-data/placement/group-name
iwaki-placement-group
placement/host-id
専用ホストで起動している場合、そのホスト ID が返ってきます。今回は都合により専用ホストを用意しませんでした。このため、ホスト ID がないので 404 を返します。
$ curl http://169.254.169.254/latest/meta-data/placement/host-id
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
</body>
</html>
placement/partition-number
プレイスメントグループには、配置戦略が 3 つ用意されており、その内パーティションを選択していると、インスタンスが起動しているパーティションの番号を返します。
$ curl http://169.254.169.254/latest/meta-data/placement/partition-number
1
placement/region
リージョン名を返します。
$ curl http://169.254.169.254/latest/meta-data/placement/region
ap-northeast-1
おわりに
プレイスメントグループや専用ホストを利用しているケースは少ないかも知れませんが、availability-zone-id
やregion
の情報については活用の場面が多そうに思いました。
本エントリがどなたかのお役に立てれば幸いです。