Here is an example of a simple AWS Lambda function written in Java:
import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; public class HelloWorldHandler implements RequestHandler<String, String> { @Override public String handleRequest(String input, Context context) { return "Hello, " + input + "!"; } } |
This function takes a string input and returns a string output, “Hello, [input]!”.
To deploy this function to AWS Lambda, you would need to package it into a JAR file along with any dependencies, and then use the AWS Management Console, the AWS CLI, or the AWS SDKs to upload the JAR file and create a new Lambda function.
In order to invoke the function, you can use the AWS Management Console, the AWS CLI, or the AWS SDKs to send an event to the function, which will trigger the handleRequest method and return the output.
You can also use AWS SAM(Serverless Application Model) or Terraform to package and deploy the function to AWS Lambda
It’s also important to note that you need to configure appropriate IAM role for the lambda function to access other resources.