Unable to connect to S3 and read a file
DeanZi opened this issue · 2 comments
DeanZi commented
package fs2
package aws
//import java.util.concurrent.Executors
import cats.effect.{Blocker, ContextShift, IO}
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import fs2.aws.internal.S3Client
import fs2.aws.s3._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import scala.concurrent.ExecutionContext
class S3Spec extends AnyFlatSpec with Matchers {
//private val blockingEC = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(6))
implicit val ec: ExecutionContext = ExecutionContext.global
implicit val ioContextShift: ContextShift[IO] = IO.contextShift(ec)
implicit val s3Client: S3Client[IO] = fs2.aws.utils.s3TestClient
val provider = new AWSStaticCredentialsProvider(
new BasicAWSCredentials("...","...")
)
val client = AmazonS3ClientBuilder
.standard
.withCredentials(provider)
.withRegion("eu-west-1") // or whatever your region is
.build
val reader: Stream[IO, Unit] = Stream.resource(Blocker[IO]).flatMap { blocker =>
readS3FileMultipart[IO]("...", "text", 25, client)
.through(fs2.text.utf8Decode)
.through(fs2.text.lines)
.intersperse("\n")
.through(text.utf8Encode)
.through(io.file.writeAll(java.nio.file.Paths.get("output.txt"), blocker))
}
reader.compile.drain.unsafeRunSync
}
getting the following error:
An exception or error caused a run to abort.
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:129)
at scala.io.BufferedSource.reader(BufferedSource.scala:26)
at scala.io.BufferedSource.bufferedReader(BufferedSource.scala:27)
at scala.io.BufferedSource.charReader$lzycompute(BufferedSource.scala:37)
at scala.io.BufferedSource.charReader(BufferedSource.scala:35)
at scala.io.BufferedSource.scala$io$BufferedSourcedecachedReader(BufferedSource.scala:64) at scala.io.BufferedSource.mkString(BufferedSource.scala:93) at fs2.aws.utils.packagedecachedReader(BufferedSource.scala:64)atscala.io.BufferedSource.mkString(BufferedSource.scala:93)atfs2.aws.utils.packageanon$1.$anonfun$getObjectContentOrError$1(package.scala:27)
barryoneill commented
Thanks for the bug report!
Looks like it's picking up the test s3 client that's in implicit scope, rather than the explicit one that you're trying to pass in. If you remove the implicit
s3TestClient it should hopefully use the client you're creating.
semenodm commented
closing because of no response