调用lambda函数时执行失败

时间:2021-07-13 10:11:10

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.

我试图调用由S3Event触发的lambda函数,我也创建了一个桶,还在桶中添加了两个图像。

below are the specifications of bucket.

以下是水桶的规格。

调用lambda函数时执行失败

Below is my code which I have written in java

下面是我用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

com.amazonaws.services.lambda.runtime.events.S3Event不存在

1 个解决方案

#1


1  

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.

并在您的类中实现“RequestHandler”接口。

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

如果问题仍然存在,请遵循本教程:AWS Lambda with S3进行实时数据处理

Hope this will help !

希望这会有所帮助!

#1


1  

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.

并在您的类中实现“RequestHandler”接口。

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

如果问题仍然存在,请遵循本教程:AWS Lambda with S3进行实时数据处理

Hope this will help !

希望这会有所帮助!