简体   繁体   中英

Running a Java function as an AWS Lambda function

I have created the following java class

  import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.Context; 

   public class SayHello implements RequestHandler<Request, Response> {

   public Response handleRequest(Request request, Context context) 
   {
       System.out.println("Running lambda function 123abc");
       return new Response("Lambda says hello");
   }
}

I have bundled this into a jar called myjar.jar and created a lambda function via my AWS console

在此处输入图片说明

I have selected Java 8 runtime, uploaded my jar so now stuck at what to do next. I have created a Cloudwatch 在此处输入图片说明 event to be triggered by launch of an EC2 instance and added the target for this event as being my Lambda function. So what next? Specifically the message "This function contains external libraries. Uploading a new file will override these libraries." puzzles me. I just want to get the lambda function to execute when the cloudwatch event happens.
Also , where can I see the output of a System.out.println command when I eventually get this to run?

You need to tell Lambda what the name of your handler function is. In Java, you would indicate this in one of two ways:

  1. as package.class::method , for example: com.mycompany.HelloWorld::handleRequest
  2. as package.class , for example: com.mycompany.HelloWorld

It's not clear how Lambda infers the name of the handler method in #2 (for example if there were two handler methods). It may simply be looking for handleRequest or it may use reflection in some way.

Anything that your Lambda function outputs will be sent to CloudWatch Logs. You can get there from the Monitoring tab of your Lambda function (or you could simply open up the CloudWatch Logs console and navigate from there).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM