My current AWS setup is a lambda function that is being triggered whenever I put an object into a S3 bucket. I implemented the lambda's handler function in Java. What I want to do is simply accessing the file that was uploaded and triggered the execution of the lambda function. E.g., if I upload sample.json to the bucket, I want to access the contents of this file in my handler function.
I know I can do something like this:
public Void handleRequest(S3Event input, Context context) {
for (S3EventNotificationRecord record : input.getRecords()) {
String key = record.getS3().getObject().getKey();
String bucket = record.getS3().getBucket().getName();
AmazonS3 s3Client = new AmazonS3Client(credentials);
try {
S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucket, key));
InputStream input = s3Object.getObjectContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
while (true) {
String line = reader.readLine();
if (line == null) break;
// Do something with line...
}
// ...
The problem is that I am not allowed to use access keys. Thus, I cannot create an s3Client to download the file with. In other words, I have to get the object from the argument that my handler method takes, i.e., S3Event input. How would I do that?
S3Event input? - Dwight Schrutes3Client.getObject(new GetObjectRequest(bucket, key));seems like a good approach. What's wrong with that? - cy3ers3Client, I need to provide access keys, which is what I want to avoid. Like @dashmug said, the lambda function handler should be able to access the file without access keys. - Dwight Schrute