简体   繁体   中英

How do I get a specific tag value from an EC2 instance using Ruby

Basically I want to get a specific tag value from an EC2 Instance. The EC2 instance has a releaseId tag key I want to retrieve, which is an integer. How do I get the releaseId value from the instance.

require 'rubygems'
require 'aws-sdk'
require 'net/http'

metadata_endpoint = 'http://169.254.169.254/latest/meta-data/'
instance_id = Net::HTTP.get( URI.parse( metadata_endpoint + 'instance-id' ) )

I have very limited Ruby knowledge and any guidance will be appreciated. After I get the current EC2 instance_id, what do I do to get the value.

Tag values are not accessible via instance metadata service. You have to use the public EC2 API DescribeTags .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM