<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Imdsv2 on Kenno&#39;s Open Note</title>
    <link>https://blog.khmersite.net/tags/imdsv2/</link>
    <description>Recent content in Imdsv2 on Kenno&#39;s Open Note</description>
    <image>
      <title>Kenno&#39;s Open Note</title>
      <url>https://blog.khmersite.net/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</url>
      <link>https://blog.khmersite.net/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</link>
    </image>
    <generator>Hugo -- 0.154.0</generator>
    <language>en</language>
    <lastBuildDate>Sun, 07 Jul 2024 17:07:26 +1000</lastBuildDate>
    <atom:link href="https://blog.khmersite.net/tags/imdsv2/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to find instance Id from the instance metadata</title>
      <link>https://blog.khmersite.net/p/how-to-find-instance-id-from-instance-metadata/</link>
      <pubDate>Sun, 07 Jul 2024 17:07:26 +1000</pubDate>
      <guid>https://blog.khmersite.net/p/how-to-find-instance-id-from-instance-metadata/</guid>
      <description>&lt;p&gt;For instances which use version 2 of instance metadata, IMDSv2, run the following 2 commands:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[ec2-user@ip-172-31-45-35 ~]$ TOKEN=`curl -X PUT &amp;#34;http://169.254.169.254/latest/api/token&amp;#34; -H &amp;#34;X-aws-ec2-metadata-token-ttl-seconds: 21600&amp;#34;`
[ec2-user@ip-172-31-45-35 ~]$ curl -w &amp;#34;\n&amp;#34; -H &amp;#34;X-aws-ec2-metadata-token: $TOKEN&amp;#34; http://169.254.169.254/latest/meta-data/instance-id
i-04bd6066612345678
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you use IMDsv1, then there is no need generate the &lt;code&gt;TOKEN&lt;/code&gt; value first, just query the &lt;code&gt;instance-id&lt;/code&gt; directly:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[ec2-user@ip-172-31-45-35 ~]$ curl -w &amp;#34;\n&amp;#34; http://169.254.169.254/latest/meta-data/instance-id
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In my case, it returned nothing as my EC2 instances uses IMDsV2. Oh, by the way, are you aware of &lt;code&gt;-w&lt;/code&gt; or &lt;code&gt;--write-out&lt;/code&gt; flag for &lt;code&gt;curl&lt;/code&gt;? It&amp;rsquo;s pretty cool, you can use it to inject a newline character
e.g. &lt;code&gt;&amp;quot;\n&amp;quot;&lt;/code&gt; to the end of output from the curl command.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
