sparrowTrajon
sparrowTrajon

Reputation: 180

execution failed while invoking the lambda function

I am trying to invoke a lambda function which is triggered by S3Event, I have created a bucket as well, also added two images into the bucket.

below are the specifications of bucket.

enter image description here

Below is my code which I have written in java

  public String handleRequest(S3Event event, Context context) {
    context.getLogger().log("Received event: " + event);

    // Get the object from the event and show its content type
    String bucket = event.getRecords().get(0).getS3().getBucket().getName();
    String key = event.getRecords().get(0).getS3().getObject().getKey();
    try {
        S3Object response = s3.getObject(new GetObjectRequest(bucket, key));
        String contentType = response.getObjectMetadata().getContentType();
        context.getLogger().log("CONTENT TYPE: " + contentType);
        return contentType;
    } catch (Exception e) {
        e.printStackTrace();
        context.getLogger().log(String.format(
            "Error getting object %s from bucket %s. Make sure they exist and"
            + " your bucket is in the same region as this function.", bucket, key));
        throw e;
    }
}

and below is the error I am getting

com.amazonaws.services.lambda.runtime.events.S3Event not present

Upvotes: 0

Views: 569

Answers (1)

Shashi Bhushan
Shashi Bhushan

Reputation: 690

Code looks fine, Confirm that you have this package imported :

com.amazonaws.services.lambda.runtime.events.S3Event

And implement the interface "RequestHandler" with your class.

If issue still persist follow this tutorial: AWS Lambda with S3 for real-time data processing

Hope this will help !

Upvotes: 1

Related Questions