How large is the file?

If it is very large then you should have anyway several partitions for the output. This is also important in case you need to read again from S3 - having several files there enables parallel reading.

On 23. Jan 2018, at 23:58, Vasyl Harasymiv <> wrote:

Hi Spark Community,

Saving a data frame into a file on S3 using:


If run for longer than 30 mins, the following error persists:

The provided token has expired. (Service: Amazon S3; Status Code: 400; Error Code: ExpiredToken;`)

Potentially, because there is a hardcoded session limit in temporary S3 connection from Spark.

One can specify the duration as per here:

One can, of course, chunk data into sub-30 min writes. However, Is there a way to change the token expiry parameter directly in Spark before using "write.csv"?

Thanks a lot for any help!

On Tue, Jan 23, 2018 at 2:46 PM, Toy <> wrote:
Thanks, I get this error when I switched to s3a://

Exception in thread "streaming-job-executor-0" java.lang.NoSuchMethodError:<init>(Lcom/amazonaws/services/s3/AmazonS3;Ljava/util/concurrent/ThreadPoolExecutor;)V
at org.apache.hadoop.fs.s3a.S3AFileSystem.initialize(
at org.apache.hadoop.fs.FileSystem.createFileSystem(

On Tue, 23 Jan 2018 at 15:05 Patrick Alwell <> wrote:

Spark cannot read locally from S3 without an S3a protocol; you’ll more than likely need a local copy of the data or you’ll need to utilize the proper jars to enable S3 communication from the edge to the datacenter.


Here are the jars:


Looks like you already have them, in which case you’ll have to make small configuration changes, e.g. s3 à s3a


Keep in mind: The Amazon JARs have proven very brittle: the version of the Amazon libraries must match the versions against which the Hadoop binaries were built.





From: Toy <>
Date: Tuesday, January 23, 2018 at 11:33 AM
To: "" <>
Subject: I can't save DataFrame from running Spark locally




First of all, my Spark application runs fine in AWS EMR. However, I'm trying to run it locally to debug some issue. My application is just to parse log files and convert to DataFrame then convert to ORC and save to S3. However, when I run locally I get this error /orc/dt=2018-01-23 doesn't exist

at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.get(

at org.apache.hadoop.fs.s3.Jets3tFileSystemStore.retrieveINode(

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(

at sun.reflect.DelegatingMethodAccessorImpl.invoke(

at java.lang.reflect.Method.invoke(



at com.sun.proxy.$Proxy22.retrieveINode(Unknown Source)

at org.apache.hadoop.fs.s3.S3FileSystem.getFileStatus(

at org.apache.hadoop.fs.FileSystem.exists(


at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:58)

at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:56)

at org.apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:74)

at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:114)

at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:114)

at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:135)

at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)

at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:132)

at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:113)

at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:87)

at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:87)

at org.apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:492)



at Vivace$$anonfun$processStream$1.apply(vivace.scala:193)

at Vivace$$anonfun$processStream$1.apply(vivace.scala:170)


Here's what I have in sbt


scalaVersion := "2.11.8"


val sparkVersion = "2.1.0"

val hadoopVersion = "2.7.3"

val awsVersion = "1.11.155"


lazy val sparkAndDependencies = Seq(

  "org.apache.spark" %% "spark-core" % sparkVersion,

  "org.apache.spark" %% "spark-sql" % sparkVersion,

  "org.apache.spark" %% "spark-hive" % sparkVersion,

  "org.apache.spark" %% "spark-streaming" % sparkVersion,


  "org.apache.hadoop" % "hadoop-aws" % hadoopVersion,

  "org.apache.hadoop" % "hadoop-common" % hadoopVersion



And this is where the code failed


val sparrowWriter = sparrowCastedDf.write.mode("append").format("orc").option("compression", "zlib")


sparrowOutputPath is something like s3://bucket/folder and it exists I checked it with aws command line


I put a breakpoint there and the full path looks like this s3://bucket/orc/dt=2018-01-23 which exists.


I have also set up the credentials like this


sc.hadoopConfiguration.set("fs.s3.awsAccessKeyId", "key")

sc.hadoopConfiguration.set("fs.s3.awsSecretAccessKey", "secret")


My confusion is this code runs fine in the cluster but I get this error running locally.