Mik*_*keH 4 java amazon-web-services aws-lambda
有没有人成功为S3事件实现了基于Java的请求处理程序?
我的课:
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.s3.model.S3Event;
public class Hello implements RequestHandler<S3Event, String> {
public String handleRequest(S3Event event, Context context) {
return "Success";
}
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
JSON解析期间发生错误:java.lang.RuntimeException java.lang.RuntimeException:JSON解析期间发生错误引起:java.io.UncheckedIOException:com.fasterxml.jackson.databind.JsonMappingException:无法反序列化com的实例. amazonaws.services.s3.model.S3Event在[来源:lambdainternal.util.NativeMemoryAsInputStream@6108b2d7;来自:START_OBJECT标记; line:1,column:1]引起:com.fasterxml.jackson.databind.JsonMappingException:无法在[Source:lambdainternal.util.NativeMemoryAsInputStream]的START_OBJECT标记中反序列化com.amazonaws.services.s3.model.S3Event的实例@ 6108b2d7; com:fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)中的com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:835)位于com.fasterxml的第1行,第1列:第1列.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:831)at com.fasterxml.jackson.databind.deser.std.EnumDeserializer._deserializeOther(EnumDeserializer.java:137)at com.fasterxml.jackson.databind.deser.std .inumDeserializer.deserialize(EnumDeserializer.java:89)at com.fasterxml.jackson.databind.deser.std.EnumDeserializer.deserialize(EnumDeserializer.java:18)at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java) :1441)at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1047)
Mik*_*keH 10
解决方案是采取S3EventNotification.希望AWS文档中包含这些内容.我喜欢Lambda概念,但没有太多的文档或示例.
public void mergeGLAU(S3EventNotification notification, Context context) {
try {
for (S3EventNotificationRecord record : notification.getRecords()) {
System.out.println(record.getEventSource());
System.out.println(record.getEventName());
System.out.println(record.getS3().getBucket().getName());
System.out.println(record.getS3().getObject().getKey());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |