title: How to read input from S3 in a Spark Streaming EC2 cluster application
body: <p>I'm trying to make my Spark Streaming application reading his input from a S3 directory but I keep getting this exception after launching it with spark-submit script:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: AWS Access Key ID and Secret Access Key must be specified as the username or password (respectively) of a s3n URL, or by setting the fs.s3n.awsAccessKeyId or fs.s3n.awsSecretAccessKey properties (respectively).
      at org.apache.hadoop.fs.s3.S3Credentials.initialize(S3Credentials.java:66)
      at org.apache.hadoop.fs.s3native.Jets3tNativeFileSystemStore.initialize(Jets3tNativeFileSystemStore.java:49)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:82)
      at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:59)
      at org.apache.hadoop.fs.s3native.$Proxy6.initialize(Unknown Source)
      at org.apache.hadoop.fs.s3native.NativeS3FileSystem.initialize(NativeS3FileSystem.java:216)
      at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1386)
      at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
      at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1404)
      at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
      at org.apache.hadoop.fs.Path.getFileSystem(Path.java:187)
      at org.apache.spark.streaming.StreamingContext.checkpoint(StreamingContext.scala:195)
      at MainClass$.main(MainClass.scala:1190)
      at MainClass.main(MainClass.scala)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:292)
      at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:55)
      at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
  </code></pre>
  
  <p>I'm setting those variables through this block of code as suggested here <a href="http://spark.apache.org/docs/latest/ec2-scripts.html" rel="noreferrer">http://spark.apache.org/docs/latest/ec2-scripts.html</a> (bottom of the page):</p>
  
  <pre><code>val ssc = new org.apache.spark.streaming.StreamingContext(
    conf,
    Seconds(60))
  ssc.sparkContext.hadoopConfiguration.set("fs.s3n.awsAccessKeyId",args(2))
  ssc.sparkContext.hadoopConfiguration.set("fs.s3n.awsSecretAccessKey",args(3))
  </code></pre>
  
  <p>args(2) and args(3) are my AWS Access Key ID and Secrete Access Key of course.</p>
  
  <p>Why it keeps saying they are not set? </p>
  
  <p>EDIT: I tried also this way but I get the same exception:</p>
  
  <pre><code>val lines = ssc.textFileStream("s3n://"+ args(2) +":"+ args(3) + "@&lt;mybucket&gt;/path/")
  </code></pre>