title: Seahorse::Client::NetworkingError Amazon S3 file upload with rails
body: <p>In my rails 4 application I'm trying to download and then upload a regular png file to my s3 bucket using the aws-sdk (using <code>gem 'aws-sdk', '~&gt; 2'</code>).</p>
  
  <p>In development environment, the code works totally fine. But if I try <code>rails s -e production</code> or if I test out the upload on my heroku instance, I get the following error when I test out the image upload functionality,</p>
  
  <pre><code>Seahorse::Client::NetworkingError (Connection reset by peer):
    app/helpers/aws_s3.rb:73:in `upload_to_s3'
    app/controllers/evaluations_controller.rb:19:in `test'
  </code></pre>
  
  <p>my upload_to_s3 method mentioned in the trace looks like:</p>
  
  <pre><code>def upload_to_s3(folder_name)
    url = "http://i.imgur.com/WKeQQox.png"
    filename = "ss-" + DateTime.now.strftime("%Y%d%m-%s") + "-" + SecureRandom.hex(4) + ".png"
    full_bucket_path = Pathname(folder_name.to_s).join(filename).to_s
    file = save_to_tempfile(url, filename)
    s3 = Aws::S3::Resource.new(access_key_id: ENV["IAM_ID"], secret_access_key: ENV["IAM_SECRET"], region: 'us-east-1')
    s3_file = s3.bucket(ENV["BUCKET"]).object(full_bucket_path)
    s3_file.upload_file(file.path)
    raise s3_file.public_url.to_s.inspect
  end
  </code></pre>
  
  <p>The environment variables are the same between both environments. I don't really know where else to turn to debug this. Why would it work in development, but not in production? I have a feeling I'm missing something pretty obvious.</p>
  
  <p>UPDATE:</p>
  
  <p>Let's simplify this further since I'm not getting very much feedback.</p>
  
  <pre><code>s3 = Aws::S3::Resource.new
  bucket = s3.bucket(ENV["BUCKET"])
  bucket.object("some_file.txt").put(body:'Hello World!')
  </code></pre>
  
  <p>The above totally works in my development environment, but not my production environment. In production it faults when I call <code>put(body:'Hello World!')</code>. I know this is probably related to write permissions or something, but again, I've checked my environment variables, and they are identical. Is there some configuration that I'm not aware of that I should be checking?</p>
  
  <p>I've tried using a new IAM user. I also temporarily copied the entire contents of development.rb over to production.rb just to see if the configuration for the development or production was affecting it, to no avail. I ran bundle update as well. Again, no luck.</p>
  
  <p>I wish the error was more descriptive, but it just says <code>Seahorse::Client::NetworkingError (Connection reset by peer)</code> no matter what I try.</p>