lundi 31 août 2015

How do I switch elastic IPs on a Linux AWS without getting disconnected from XShell?

I'm using XShell to access a Linux AWS. I know how to switch elastic IP addresses with Ruby, but when I do, XShell's connection to the AWS gets busted.

Here's script.rb I run on the AWS via XShell with the ruby script.rb command:

require 'json'
require 'pp'

region = 'REGION NAME'
aws_access_key_id = 'SECRET KEY ID'
aws_secret_access_key = 'SECRET ACCESS KEY'
credentials = Aws::Credentials.new(aws_access_key_id, aws_secret_access_key)
client = Aws::EC2::Client.new(
    region: region,
    credentials: credentials
)
pp client
p '==='

describeAddresses = `aws ec2 describe-addresses`
awsHash = JSON.parse(describeAddresses)
pp awsHash
p '==='

getInstanceID = `wget -O - 'http://ift.tt/1IpSH7i' 2>/dev/null`
instanceID = getInstanceID.split("\n")[-1]
pp instanceID
p '==='

resp = client.allocate_address({
  domain: "vpc", # accepts vpc, standard
})
pp resp
p '==='

resp2 = client.associate_address({
    instance_id: instanceID,
    allocation_id: resp['allocation_id'],
    allow_reassociation: true#,
})
pp resp2
p '==='




Aucun commentaire:

Enregistrer un commentaire