我有一个功能
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
其目的是将s3上某个对象的数据转换为惰性字节串。
发送请求成功,我可以看到响应。当然,gorsBody
字段显示为RsBody { ConduitM () ByteString (ResourceT IO) () }
,因为它就是它。
当我尝试函数的最后一行时,我得到的是这样的:
*** 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
这似乎与懒惰有关;也许在关闭连接之前从未评估响应主体。但这纯粹是猜测,无论如何,我不确定该如何解决。有人知道这里发生了什么吗?看来我在做的是正确使用amazonka-s3 + conduit。
我正在使用lts-11.14
和amazonka-s3-1.6.0
。
答案 0 :(得分:1)
事实证明,这是amazonka-s3
的Stackage版本的known issue,尚未修复。解决方法是升级amazonka / core / s3依赖项以指向主版本的固定版本:
# stack.yaml
extra-deps:
- git: git@github.com:brendanhay/amazonka
commit: 248f7b2a7248222cc21cef6194cd1872ba99ac5d
subdirs:
- amazonka
- core
- amazonka-s3