当前位置: 首页>>代码示例>>Java>>正文


Java DynamodbEvent类代码示例

本文整理汇总了Java中com.amazonaws.services.lambda.runtime.events.DynamodbEvent的典型用法代码示例。如果您正苦于以下问题:Java DynamodbEvent类的具体用法?Java DynamodbEvent怎么用?Java DynamodbEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DynamodbEvent类属于com.amazonaws.services.lambda.runtime.events包,在下文中一共展示了DynamodbEvent类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; //导入依赖的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();
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:34,代码来源:TestUtils.java

示例2: handleRequest

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; //导入依赖的package包/类
@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;
}
 
开发者ID:aws-samples,项目名称:reinvent2015-practicaldynamodb,代码行数:17,代码来源:ScoresTableTrigger.java

示例3: handleRequest

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent; //导入依赖的package包/类
@Override
public Object handleRequest(DynamodbEvent input, Context context) {
	String employeeId = "";
	String employeeName = "";
	String expenseType = "";
	Double amount = 0.0;

	for (DynamodbStreamRecord r : input.getRecords()) {
		// context.getLogger().log("Event id: "+r.getEventID());
		// context.getLogger().log("Event name: "+r.getEventName());
		// context.getLogger().log("Event source: "+r.getEventSource());
		StreamRecord sr = r.getDynamodb();
		for (Entry<String, AttributeValue> entry : sr.getNewImage()
				.entrySet()) {
			String k = entry.getKey();
			AttributeValue v = entry.getValue();
			switch (k) {
			case "employee_id":
				employeeId = v.getS();
				break;
			case "employee_name":
				employeeName = v.getS();
				break;
			case "expense_type":
				expenseType = v.getS();
				break;
			case "amount":
				amount = Double.valueOf(entry.getValue().getN());
				break;
			default:
				context.getLogger().log("Key " + k + " is unknown.");
			}
		}
	}

	context.getLogger().log(
			"ENTRY: " + employeeId + " | " + employeeName + " | "
					+ expenseType + " | " + amount);

	String from = "[email protected]"; // TODO Replace with your "From" address.
										// This address must be verified.
	String to = "[email protected]"; // TODO Replace with a "To" address. If you
										// have not yet requested production
										// access, this address must be
										// verified.
	String subject = String.format("Expense reimbursment request by %s",
			employeeName);
	// TODO Replace with your own approval URL
	String approvalUrl = String
			.format("https://.......execute-api.eu-west-1.amazonaws.com/test/reimbursment?id=%s",
					employeeId);
	String body = String
			.format("Hello boss,\n\nplease approve my expense reimbursment:\n%s\n\nExpense type: %s\nAmount: %s EUR\n\nThanks!\n%s\nEmployee ID: %s ",
					approvalUrl, expenseType, amount, employeeName,
					employeeId);
	sendMail(from, to, subject, body);
	context.getLogger().log("Email sent from " + from + " to " + to);

	return null;
}
 
开发者ID:markusklems,项目名称:aws-lambda-java-example,代码行数:61,代码来源:LambdaSendMailFunctionHandler.java


注:本文中的com.amazonaws.services.lambda.runtime.events.DynamodbEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。