I have a private method in my Rails app to connect to Amazon S3, execute a passed block of code, then close the connection to S3. It looks like so;
def S3 AWS:
You can write a module as :
module MyModule def self.S3(args*) AWS::S3::Base.establish_connection!( :access_key_id => 'Not telling', :secret_access_key => 'Really not telling' ) data = yield AWS::S3::Base.disconnect data end end
and then call it in your controller or model as
MyModule.S3(params*)