-
-
Save ashayh/3897230 to your computer and use it in GitHub Desktop.
aws ec2 set hostname by tag name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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