Skip to content

Instantly share code, notes, and snippets.

@johnschult
Last active August 29, 2015 14:02
Show Gist options
  • Save johnschult/0059b9826e1f752ad001 to your computer and use it in GitHub Desktop.
Save johnschult/0059b9826e1f752ad001 to your computer and use it in GitHub Desktop.
EC2 show instance tags
require 'rubygems'
require 'aws-sdk'
LAYER = 'boxcast_origin'
STACK = 'dev.boxcast.com'
TAG_PREFIX = 'boxcast:origin'
ec2 = AWS::EC2.new()
boxcast_origin_instances = []
ec2.instances.with_tag('opsworks:stack', STACK).tagged("opsworks:layer:#{LAYER}").each do |instance|
tags = {}
instance.tags.to_h.each do |k,v|
tags[k] = v if k[/^#{TAG_PREFIX}/]
end
tags['id'] = instance.id
tags['availability_zone'] = instance.availability_zone
boxcast_origin_instances << tags
end
p boxcast_origin_instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment