Reputation: 197
How will the Lambda handler of multiple different types of trigger
look like in java?
I want to set a trigger for Cloudwatch Event Rule
, S3
. How can I do this?
public class App implements RequestHandler<S3Event, Context>
{
public Context handleRequest(S3Event s3event, Context context) {
System.out.println("welcome to lambda");
}
}
Upvotes: 1
Views: 2803
Reputation: 552
You can use Map<String,String>
as input
public class Handler implements RequestHandler<Map<String,String>, String>{
@Override
public String handleRequest(Map<String,String> event, Context context) {
}
}
Or use RequestStreamHandler
and parse the InputStream to the correct object.
public class HandlerStream implements RequestStreamHandler {
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
}
}
Upvotes: 2
Reputation: 2985
using a generic Object
could work, I use Serverless Framework with:
package com.serverless;
import java.util.Collections;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Handler implements RequestHandler<Object, Object> {
private static final Logger LOG = LogManager.getLogger(Handler.class);
@Override
public Object handleRequest(final Object input, final Context context) {
LOG.info("received: {}", input);
return input;
}
}
Upvotes: 0