Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Created June 7, 2012 07:48
Show Gist options
  • Save hSATAC/2887240 to your computer and use it in GitHub Desktop.
Save hSATAC/2887240 to your computer and use it in GitHub Desktop.
aws ec2 set hostname by tag name
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
instance_id = `wget "http://169.254.169.254/latest/meta-data/instance-id" -o /dev/null -O /dev/stdout`
config = {:access_key_id => '',
:secret_access_key => ''}
AWS.config(config)
ec2 = AWS::EC2.new
ec2 = ec2.regions['ap-northeast-1']
hostname = ec2.instances[instance_id].tags.to_h["Name"]
`hostname #{hostname}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment