title: Reading a file on aws s3 with a Java lambda
body: <p><strong>CONTEXT :</strong></p>
  
  <p>I am trying to read a csv file on AWS s3, compute its data and write the results on another csv in the same s3 bucket.</p>
  
  <p>I tried the following code to create a class that would read my <code>Main</code>, with arguments stored in a text file named <code>lambdaCmd.txt</code>. Each time <code>lambdaCmd.txt</code> is modified, the lambda function is triggered and the content of <code>lambdaCmd.txt</code> is passed to the following class via the <code>s3event</code> parameter :</p>
  
  <pre><code>public class LambdaCmd implements RequestHandler&lt;S3Event, Void&gt;{
  
      static final Logger LOGGER = LogManager.getLogger(LambdaCmd.class);
  
      @Override
      public Void handleRequest(S3Event s3event, Context context) {
  
          //Getting my txt file's path
          S3EventNotification.S3EventNotificationRecord record = s3event.getRecords().get(0);
          String bkt = record.getS3().getBucket().getName();
          String key = record.getS3().getObject().getKey().replace('+', ' ');
          try {
              key = URLDecoder.decode(key, "UTF-8");
          } catch (UnsupportedEncodingException ex) {
              LOGGER.error(ex);
          }
  
          AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();
  
          try {
  
              //Getting my text file as a String Stream
              InputStreamReader cmdStream =
                  new InputStreamReader(s3Client.getObject(bkt, key).getObjectContent());
              BufferedReader br = new BufferedReader(cmdStream);
  
              //Parsing the command in cmdStream
              //...
              //The command is now "String[] cmdArray" to be passed to my main
  
              MyMain.main(cmdArray);
              //The main function reads and write from s3 with a similar use of s3Client
  
              br.close();
  
          } catch (IOException | IllegalArgumentException | NullPointerException ex) {
              LOGGER.error(ex);
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p><strong>PROBLEM :</strong></p>
  
  <p>After logging some debug messages in this code, I figured out that the lambda function stops at this line :</p>
  
  <pre><code>        AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();
  </code></pre>
  
  <p>Here is the CloudWatch log (I hide personal information with <code>##########</code>):</p>
  
  <pre><code>START RequestId: ########## Version: $LATEST
  16:12:11.596 [main] DEBUG path.to.mylambdaclass.LambdaCmd - LambdaCmd started
  16:12:11.616 [main] DEBUG path.to.mylambdaclass.LambdaCmd - Just before creating s3Client
  END RequestId: ##########
  REPORT RequestId: ##########    Duration: 12398.45 ms   Billed Duration: 12400 ms Memory Size: 128 MB   Max Memory Used: 67 MB
  </code></pre>
  
  <p>I also have a log message just after creating <code>s3Client</code>, but it is not printed in logs.</p>
  
  <p><strong>QUESTION :</strong></p>
  
  <p>Why is my lambda ending prematurely? Do I misuse some objects?</p>