本文整理汇总了Java中com.amazonaws.services.s3.event.S3EventNotification.getRecords方法的典型用法代码示例。如果您正苦于以下问题:Java S3EventNotification.getRecords方法的具体用法?Java S3EventNotification.getRecords怎么用?Java S3EventNotification.getRecords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.event.S3EventNotification
的用法示例。
在下文中一共展示了S3EventNotification.getRecords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.amazonaws.services.s3.event.S3EventNotification; //导入方法依赖的package包/类
/**
* Helper method that parses a JSON object from a resource on the classpath
* as an instance of the provided type.
*
* @param resource
* the path to the resource (relative to this class)
* @param clazz
* the type to parse the JSON into
*/
public static <T> T parse(String resource, Class<T> clazz)
throws IOException {
InputStream stream = TestUtils.class.getResourceAsStream(resource);
try {
if (clazz == S3Event.class) {
String json = IOUtils.toString(stream);
S3EventNotification event = S3EventNotification.parseJson(json);
@SuppressWarnings("unchecked")
T result = (T) new S3Event(event.getRecords());
return result;
} else if (clazz == SNSEvent.class) {
return snsEventMapper.readValue(stream, clazz);
} else if (clazz == DynamodbEvent.class) {
return dynamodbEventMapper.readValue(stream, clazz);
} else {
return mapper.readValue(stream, clazz);
}
} finally {
stream.close();
}
}
示例2: parse
import com.amazonaws.services.s3.event.S3EventNotification; //导入方法依赖的package包/类
/**
* Helper method that parses a JSON object from a resource on the classpath
* as an instance of the provided type.
*
* @param resource the path to the resource (relative to this class)
* @param clazz the type to parse the JSON into
*/
public static <T> T parse(String resource, Class<T> clazz)
throws IOException {
InputStream stream = TestUtils.class.getResourceAsStream(resource);
try {
if (clazz == S3Event.class) {
String json = IOUtils.toString(stream);
S3EventNotification event = S3EventNotification.parseJson(json);
@SuppressWarnings("unchecked")
T result = (T) new S3Event(event.getRecords());
return result;
} else {
return mapper.readValue(stream, clazz);
}
} finally {
stream.close();
}
}
示例3: handler
import com.amazonaws.services.s3.event.S3EventNotification; //导入方法依赖的package包/类
@Override
public void handler(SNSEvent event, Context context) throws HandlerException {
if (!initialized) {
init(context);
}
this.source = this.sources.get(0);
this.inputFiles = new ArrayList<String>(0);
for (SNSRecord record : event.getRecords()) {
/*
* Parse SNS as a S3 notification
*/
String json = record.getSNS().getMessage();
S3EventNotification s3Event = S3EventNotification.parseJson(json);
/*
* Validate the S3 file matches the regex
*/
List<S3EventNotificationRecord> toProcess =
new ArrayList<S3EventNotificationRecord>(s3Event.getRecords());
for (S3EventNotificationRecord s3Record : s3Event.getRecords()) {
String s3Path = String.format("s3://%s/%s", s3Record.getS3().getBucket().getName(),
s3Record.getS3().getObject().getKey());
try {
this.source = SourceUtils.getSource(s3Path, this.sources);
} catch (SourceNotFoundException e) {
logger.warn("skipping processing " + s3Path);
toProcess.remove(s3Record);
}
}
if (toProcess.size() == 0) {
logger.warn("Nothing to process");
return;
}
this.inputFiles.addAll(toProcess.stream().map(m -> {
return m.getS3().getObject().getKey();
}).collect(Collectors.toList()));
this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);
super.process(context);
}
}
示例4: handler
import com.amazonaws.services.s3.event.S3EventNotification; //导入方法依赖的package包/类
public void handler(S3EventNotification event, Context context) throws HandlerException {
if (!initialized) {
init(context);
}
/*
* Validate the S3 file matches the regex
*/
List<S3EventNotificationRecord> toProcess =
new ArrayList<S3EventNotificationRecord>(event.getRecords());
for (S3EventNotificationRecord record : event.getRecords()) {
String s3Path = String.format("s3://%s/%s", record.getS3().getBucket().getName(),
record.getS3().getObject().getKey());
try {
this.source = SourceUtils.getSource(s3Path, this.sources);
} catch (SourceNotFoundException e) {
logger.warn("Skipping processing " + s3Path);
toProcess.remove(record);
}
}
if (toProcess.size() == 0) {
logger.warn("Nothing to process");
return;
}
this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);
super.process(context);
}