Introducing the EC2i3 gem

require 'ec2i3'

reg = XMLRegistry.new '/home/james/da2/registry/registry.xml'
e = EC2i3.new reg, address: '192.168.4.140'
e.start 'windows', duration: 2

The above example fetches the Amazon Web Services (AWS) credentials from the XML registry, launches the Windows EC2 instance, and then publishes the public IP address to the SimplePubSub broker. After 2 minutes the Windows EC2 instance is stopped, and a further SimplePubSub message is published to notify subscribers of topic EC2i3 that the instance is stopping.

How to create a ec2i3.reg file for importing into the XML registry

Before running this script you need to have a valid AWS access_key + AWS private_key, and have generated a Dynarex-password lookup file.

require 'leetpassword'
require 'dynarex-password'
require 'encrypt'

access_key = 'your_aws_accessid'
private_key = 'your_aws_privatekey'
lookup_file = '/home/james/password-010915.xml'

dp = DynarexPassword.new
passphrase = LeetPassword.generate(8)
encrypted_passphrase = dp.lookup(passphrase, lookup_file)

encrypted_private_key = Encrypt.dump(private_key, passphrase).\
                                                   each_byte.to_a.join(' ')
private_key = Encrypt.load(encrypted_private_key.\
                             split(' ').map(&:to_i).pack('C*'), passphrase)

s = "
hkey_apps/ec2i3
access_key_id: #{access_key}
private_key: #{encrypted_private_key}
lookup_file: #{lookup_file}
passphrase: #{encrypted_passphrase}
"

File.write 'ec2i3.reg', s

Resources