starterApps/aws-java-mvn-tryout-service/src/main/java/com/serverless/Handler.java
<gh_stars>0package 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<Map<String, Object>, ApiGatewayResponse> {

	private static final Logger LOG = LogManager.getLogger(Handler.class);

	@Override
	public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
		// This LOG will go into the CloudWatch Logs, not in the normal IntelliJIDEA console
		LOG.info("received: {}", input); // input -> is data to be received //sls invoke --function hello --path data.json --log // here, input would be <data.json>

		Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully!", input);
		return ApiGatewayResponse.builder()
				.setStatusCode(200)
				.setObjectBody(responseBody)
				.setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless")) // Collections.singletonMap means immutable map, having only one key-value pair
				.build();
	}
}
