haskellamazon-s3conduit

`ConnectionClosed` when using `getObject` from amazonka-s3


I have a function

import Control.Lens ((^.))
import Data.Conduit (sinkLazy)
import Network.AWS (MonadAWS, send, sinkBody)
import Network.AWS.S3 (BucketName (..), ObjectKey (..), gorsBody, getObject)
import qualified Data.ByteString.Lazy as LBS


getObjectData :: MonadAWS m => Text -> Text -> m LBS.ByteString
getObjectData b k = do
  resp <- send $ getObject (BucketName b) (ObjectKey k)
  (resp ^. gorsBody) `sinkBody` sinkLazy

whose purpose is to get the data from some object on s3 into a lazy bytestring.

Sending the request is successful, and I can see the response. Of course, the gorsBody field is shown as RsBody { ConduitM () ByteString (ResourceT IO) () } because that is what it is.

When I try the last line of the function, I get something like this:

*** Exception: HttpExceptionRequest Request {
  host                 = "s3.amazonaws.com"
  port                 = 443
  secure               = True
  requestHeaders       = [("Host","s3.amazonaws.com"),("X-Amz-Date","20181121T001938Z"),("X-Amz-Content-SHA256","blah"),("X-Amz-Security-Token","blah"),("Authorization","<REDACTED>")]
  path                 = "/path/to/my/file.txt"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 0
  responseTimeout      = ResponseTimeoutMicro 70000000
  requestVersion       = HTTP/1.1
}
 ConnectionClosed

It sort of seems like this might have something to do with laziness; maybe that the response body was never evaluated before the connection was closed. But that's pure speculation, and in any case, I am not sure how to address it. Does anyone have an idea of what is happening here? It seems like what I'm doing is the right use of amazonka-s3+conduit.

I'm using lts-11.14 and amazonka-s3-1.6.0.


Solution

  • As it turns out, this is a known issue with the Stackage release of amazonka-s3, which hasn't been fixed yet. The workaround is to upgrade the amazonka/core/s3 dependencies to point to a fixed version of master:

    # stack.yaml
    extra-deps:
    - git: git@github.com:brendanhay/amazonka
      commit: 248f7b2a7248222cc21cef6194cd1872ba99ac5d
      subdirs:
        - amazonka
        - core
        - amazonka-s3