View a markdown version of this page

使用 Snowball Edge IMDSv1 和 IMDSv2 在 Snowball Edge 上检索实例元数据的示例 - Amazon Snowball Edge 开发人员指南
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

Amazon Snowball Edge 不再向新客户提供。新客户应探索Amazon DataSync在线传输、用于安全物理传输Amazon 的数据传输终端或 Amazon 合作伙伴解决方案。对于边缘计算,请浏览 Amazon Out posts。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Snowball Edge IMDSv1 和 IMDSv2 在 Snowball Edge 上检索实例元数据的示例

以下示例提供了可以在 Linux 实例上使用的命令。

例获取实例元数据的可用版本

此示例可以获取实例元数据的可用版本。当有新的实例元数据类别发布时,每个版本都引用一个实例元数据构建。如果您有依赖于以前版本中所存在的结构和信息的脚本,则您可使用早期版本。

IMDSv2

[ec2-user ~]$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 56 100 56 0 0 3733 0 --:--:-- --:--:-- --:--:-- 3733 * Trying 169.254.169.254... * TCP_NODELAY set * Connected to 169.254.169.254 (169.254.169.254) port 80 (#0) > GET / HTTP/1.1 > Host: 169.254.169.254 > User-Agent: curl/7.61.1 > Accept: */* > X-aws-ec2-metadata-token: MDAXcxNFLbAwJIYx8KzgNckcHTdxT4Tt69TzpKExlXKTULHIQnjEtXvD > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Date: Mon, 12 Sep 2022 21:58:03 GMT < Content-Length: 274 < Content-Type: text/plain < Server: EC2ws < 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15 2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 2018-03-28 2018-08-17 2018-09-24 2019-10-01 2020-10-27 2021-01-03 2021-03-23 * Closing connection 0

IMDSv1

[ec2-user ~]$ curl http://169.254.169.254/ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15 2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 2018-03-28 2018-08-17 2018-09-24 2019-10-01 2020-10-27 2021-01-03 2021-03-23 latest
例获取顶级元数据项

此示例获得顶级元数据项目。有关顶级元数据项的信息,请参阅本指南中的支持的实例元数据和用户数据。

IMDSv2

[ec2-user ~]$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/ ami-id hostname instance-id instance-type local-hostname local-ipv4 mac network/ reservation-id security-groups

IMDSv1

[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/ ami-id hostname instance-id instance-type local-hostname local-ipv4 mac network/ reservation-id security-groups
例获取顶级元数据的值

以下示例获取在前面的示例中获取的某些顶级元数据项的值。这些 IMDSv2 请求使用在前面的示例命令中创建的存储令牌,前提是该令牌尚未过期。

ami‐id IMDSv2

curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/ami-id ami-0abcdef1234567890

ami-id IMDSv1

curl http://169.254.169.254/latest/meta-data/ami-id ami-0abcdef1234567890

reservation-id IMDSv2

[ec2-user ~]$ curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/reservation-id r-0efghijk987654321

reservation-id IMDSv1

[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/reservation-id \ r-0efghijk987654321

local-hostname IMDSv2

[ec2-user ~]$ curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/local-hostname ip-00-000-00-00

local-hostname IMDSv1

[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/local-hostname ip-00-000-00-00