title: AWS Lambda and S3 integration using AWS Java Sdk
body: <p>I am trying to develop a AWS lambda function which is triggered when a file shows up in a specific s3 bucket. I am trying to follow the examples from <a href="http://docs.aws.amazon.com/lambda/latest/dg/getting-started-create-function.html" rel="nofollow noreferrer" title="AWS Lambda documentation">AWS Lambda documentation</a>, using aws-java-sdk-lambda 1.11.192, aws-java-sdk-s3 1.11.192. But, unfortunately the these examples use RequestHandler which is deprecated in the latest version of the jar. </p>
  
  <p>My code is similar to <a href="https://stackoverflow.com/questions/30651502/how-to-get-contents-of-a-text-file-from-aws-s3-using-a-lambda-function">this example</a></p>
  
  <pre><code>package example;
  
  import java.net.URLDecoder;
  
  import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  import com.amazonaws.services.lambda.runtime.events.S3Event;
  import com.amazonaws.services.s3.AmazonS3;
  import com.amazonaws.services.s3.AmazonS3Client;
  import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord;
  
  public class S3GetTextBody implements RequestHandler&lt;S3Event, String&gt; {
  
  public String handleRequest(S3Event s3event, Context context) {
      try {
          S3EventNotificationRecord record = s3event.getRecords().get(0);
  
          // Retrieve the bucket &amp; key for the uploaded S3 object that
          // caused this Lambda function to be triggered
          String bkt = record.getS3().getBucket().getName();
          String key = record.getS3().getObject().getKey().replace('+', ' ');
          key = URLDecoder.decode(key, "UTF-8");
  
          // Read the source file as text
          AmazonS3 s3Client = new AmazonS3Client();
          String body = s3Client.getObjectAsString(bkt, key);
          System.out.println("Body: " + body);
          return "ok";
      } catch (Exception e) {
          System.err.println("Exception: " + e);
          return "error";
      }
  
    }
  }
  </code></pre>
  
  <p>The current version of the aws sdk for lambda doesn't contain - </p>
  
  <pre><code>import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  import com.amazonaws.services.lambda.runtime.events.S3Event;
  </code></pre>
  
  <p>What are my alternatives? How can I achieve similar functionality using the newer versions of their sdk.</p>