views:

59

answers:

1

I'm migrating my rails app to Heroku and need to change my file upload functionality to use Amazon S3 instead of local storage. I am using the aws-s3 gem and have this working but just want to make sure that I'm doing things right and not creating problems for myself.

In my uploading code I have the following;

AWS::S3::Base.establish_connection!(
    :access_key_id     => 'Not telling',
    :secret_access_key => 'Really not telling'
  )
AWS::S3::S3Object.store("#{self.name}", upload_file_field.read, 'my_bucket')

This works perfectly but I'm concerned that I'm leaving some sort of connection to the server open. Do I need to close the connection once I'm done (e.g. with AWS::S3::Base.disconnect) or can I just leave this as it is?

Clearly I don't have a good understanding of the protocols being used behind the scenes with my connection to S3 but I don't particularly want to - I just want to make sure that this will work without causing problems.

+2  A: 

Check here for the docs for the API, and the disconnect method in particular:

http://amazon.rubyforge.org/doc/classes/AWS/S3/Connection/Management/ClassMethods.html#M000088

It's not clear about whether you must close each connection explicitly. However, it does mention a performance increase if you open a persistent connection, this is done by default anyway.

[...]

* :persistent - Whether to use a persistent connection to the server.

Having this on provides around a two fold

performance increase but for long running processes some firewalls may find the long lived connection suspicious and close the connection. If you run into connection errors, try setting :persistent to false. Defaults to true.

fletcher
Thanks,I have decided to explicitly close the connection as I think this is appropriate given the nature of a webapp. I can't see any real disadvantage in doing it.
brad