我有以下代码:
require 'rubygems'
require 'aws-sdk'
require 'sqlite3'
require 'active_record'
db = SQLite3::Database.new('awsec2.db')
ActiveRecord::Base.establish_connection(
:adapter=> "sqlite3",
:database=> "awsec2")
ActiveRecord::Schema.define do
create_table :instances do |t|
t.column :instance_id, :string
t.column :status, :string
end
end
ACCESS_KEY_ID = '.......................'
SECRET_ACCESS_KEY = '....................'
ec2 = AWS::EC2.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
ec2.instances.inject({}) { |m, i| m[i.id] = i.status; m } # How to pass those items to the instances table
如何将ec2.instances方法收集的数据存储到数据库表中?