Java 类com.amazonaws.services.lambda.runtime.events.DynamodbEvent 实例源码

项目:jetfuel    文件:TestUtils.java   
/**
 * 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();
    }
}
项目:reinvent2015-practicaldynamodb    文件:ScoresTableTrigger.java   
@Override
public Object handleRequest(DynamodbEvent input, Context context) {
    context.getLogger().log("Input: " + input);

    DynamoDB dynamodb = new DynamoDB(Regions.US_WEST_2);

    for (DynamodbStreamRecord record : input.getRecords()) {
        Map<String, AttributeValue> newData = record.getDynamodb().getNewImage();
        if (newData == null) continue;  // ignore deletes

        Item item = Item.fromMap(InternalCalls.toSimpleMapValue(newData));
        DataTransformer.PLAYER_STATS_TRANSFORMER.transform(item, dynamodb);
    }

    return true;
}