title: Why rails app not receive the request response from google drive API on EC2, but it works in localhost?
body: <p>I have an app that calls the Google Drive API to create and copy documents in a Google Drive folder, the create method generates a folder for each <code>Test</code> and creates copies of a Google Doc (question doc) and puts them in the associated folder to the <code>Test</code> (answers).</p>
  
  <p>In localhost it works and all API responses arrive successfully, but in EC2 the response of the last request to the API doesn't arrive.</p>
  
  <p>In the app's log the request doesn't appear but if the success response of the previous Google Doc generated("200"," HTTP :: Message ... from Google Drive API").</p>
  
  <pre><code># log/production.log
  
  D, [2019-09-07T01:47:11.891256 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5] Sending HTTP post https://www.googleapis.com/drive/v3/files/1exr3HKLe6IgOZU8I22VZEV4WH24UrKnGOPvmGi8-g2k/copy?fields=id%2CwebViewLink%2Cname
  D, [2019-09-07T01:47:14.442112 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5] 200
  D, [2019-09-07T01:47:14.442366 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5] #&lt;HTTP::Message:0x000055f8e60e6d40 @http_header=#&lt;HTTP::Message::Headers:0x000055f8e60e6d18 @http_version="1.1", @body_size=0, @chunked=false, @request_method="POST", @request_uri=#&lt;Addressable::URI:0x2afc73073d44 URI:https://www.googleapis.com/drive/v3/files/1exr3HKLe6IgOZU8I22VZEV4WH24UrKnGOPvmGi8-g2k/copy?fields=id%2CwebViewLink%2Cname&gt;, @request_query=nil, @request_absolute_uri=nil, @status_code=200, @reason_phrase="OK", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#&lt;Encoding:UTF-8&gt;, @is_request=false, @header_item=[["Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"], ["Pragma", "no-cache"], ["Expires", "Mon, 01 Jan 1990 00:00:00 GMT"], ["Date", "Sat, 07 Sep 2019 01:47:14 GMT"], ["Vary", "Origin"], ["Vary", "X-Origin"], ["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["X-Content-Type-Options", "nosniff"], ["X-Frame-Options", "SAMEORIGIN"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Alt-Svc", "quic=\":443\"; ma=2592000; v=\"46,43,39\""], ["Transfer-Encoding", "chunked"]], @dumped=false&gt;, @peer_cert=#&lt;OpenSSL::X509::Certificate: subject=#&lt;OpenSSL::X509::Name CN=*.googleapis.com,O=Google LLC,L=Mountain View,ST=California,C=US&gt;, issuer=#&lt;OpenSSL::X509::Name CN=GTS CA 1O1,O=Google Trust Services,C=US&gt;, serial=#&lt;OpenSSL::BN:0x000055f8e6101028&gt;, not_before=2019-08-23 10:30:37 UTC, not_after=2019-11-21 10:30:37 UTC&gt;, @http_body=#&lt;HTTP::Message::Body:0x000055f8e60e6ca0 @body="{\n \"id\": \"1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8\",\n \"name\": \"Pregunta 2\",\n \"webViewLink\": \"https://docs.google.com/document/d/1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8/edit?usp=drivesdk\"\n}\n", @size=0, @positions=nil, @chunk_size=nil&gt;, @previous=nil&gt;
  D, [2019-09-07T01:47:14.443173 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5] Success - #&lt;Google::Apis::DriveV3::File:0x000055f8e6100768
   @id="1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8",
   @name="Pregunta 2",
   @web_view_link=
    "https://docs.google.com/document/d/1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8/edit?usp=drivesdk"&gt;
  
  D, [2019-09-07T01:47:14.443797 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5]   ^[[1m^[[35m (0.2ms)^[[0m  ^[[1m^[[35mBEGIN^[[0m
  D, [2019-09-07T01:47:14.444924 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5]   ^[[1m^[[36mAnswer Create (0.4ms)^[[0m  ^[[1m^[[32mINSERT INTO "answers" ("name", "id_google_doc", "gdrive_link", "test_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"^[[0m  [["name", "Pregunta 2"], ["id_google_doc", "1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8"], ["gdrive_link", "https://docs.google.com/document/d/1qmoh-0cTJTNesh1qmxe97Bm0BpnXlrAng3ul2Ttryn8/edit?usp=drivesdk"], ["test_id", 59], ["created_at", "2019-09-07 01:47:14.444031"], ["updated_at", "2019-09-07 01:47:14.444031"]]
  D, [2019-09-07T01:47:14.446000 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5]   ^[[1m^[[35m (0.9ms)^[[0m  ^[[1m^[[35mCOMMIT^[[0m
  D, [2019-09-07T01:47:14.446717 #12230] DEBUG -- : [3457498a-19dd-4a0a-a326-4dbf47a358c5] Sending HTTP post https://www.googleapis.com/drive/v3/files/1gtGCWyATlRkCu8yMLOifdPt_F6c2oRRwc2zLUG0HGUc/copy?fields=id%2CwebViewLink%2Cname
  </code></pre>
  
  <pre><code>  # app/controllers/tests_controller.rb
    # POST /tests
    # POST /tests.json
    def create
  
      @test = Test.new(test_params)
      @students_course = @test.test_rubric.course.students
      @questions = @test.test_rubric.questions
  
      if @test.test_rubric.tests.first.present?
        init_drive_service
        @test.test_rubric.tests.each do |old_test|
          @gdrive_service.delete_doc(old_test.id_google)
          old_test.destroy
        end
      end
  
  
      respond_to do |format|
        if @students
  
          init_drive_service
          @root_folder = Folder.find(@test.test_rubric.tests_folder_id)
          @students_course.each do |student_test|
            @test1 = Test.new(test_params)
            @test_folder = new_folder(student_test.dni,@root_folder) #create folder in Google Drive
            @test1.id_google = @test_folder.id_gdrive
            @test1.gdrive_link = @test_folder.gdrive_link
            @test1.student = student_test
            @test1.shared = false
            @test1.save
            @questions.each do |q|
              @test_answer_gdrive = @gdrive_service.copy_doc(q.name, q.id_google_doc, @test_folder.id_gdrive) # ----- HERE CRASH ----
              @answer = Answer.new(name: @test_answer_gdrive.name,
                                   id_google_doc: @test_answer_gdrive.id,
                                   gdrive_link: @test_answer_gdrive.web_view_link)
              @answer.test = @test1
              @answer.save
            end
          end
          format.html { redirect_to evaluaciones_path(curso: @test.test_rubric.course), alert: 'success', notice: @test.test_rubric.name+' - Pruebas generadas exitosamente'}
          format.json { render :show, status: :created, location: @test }
        else
          format.html { render :new }
          format.json { render json: @test.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>Could I be exceeding the Google Drive API calls limit or could I have an error in the <code>@questions.each</code> loop ?</p>