service: aws-java-maven # NOTE: update this with your service name
provider:
name: aws
runtime: java8
package:
individually: true
package com.serverless;
import java.util.Collections;
import java.util.Map;
import org.apache.log4j.BasicConfigurator;
import org.apache.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 = Logger.getLogger(Handler.class);
@Override
public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
BasicConfigurator.configure();
LOG.info("received: " + input);
Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully! - function 1", input);
return ApiGatewayResponse.builder()
.setStatusCode(200)
.setObjectBody(responseBody)
.setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless"))
.build();
}
public ApiGatewayResponse handleRequest2(Map<String, Object> input, Context context) {
Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully! - function 2", input);
return ApiGatewayResponse.builder()
.setStatusCode(200)
.setObjectBody(responseBody)
.setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless"))
.build();
}
}
functions:
hello:
handler: com.serverless.Handler::handleRequest
package:
artifact: target/hello-dev.jar
hello2:
handler: com.serverless.Handler::handleRequest2
package:
artifact: target/hello-dev.jar
This does not work with
invoke local
as of this writing (1.25.0).
bash-3.2$ mvn clean install
bash-3.2$ sls deploy
Service Information
service: aws-java-maven
stage: dev
region: us-east-1
stack: aws-java-maven-dev
api keys:
None
endpoints:
None
functions:
hello: aws-java-maven-dev-hello
hello2: aws-java-maven-dev-hello2
bash-3.2$ sls invoke -f hello
{
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v1.x! Your function executed successfully! - function 1\",\"input\":{}}",
"headers": {
"X-Powered-By": "AWS Lambda & serverless"
},
"isBase64Encoded": false
}
bash-3.2$ sls invoke -f hello2
{
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v1.x! Your function executed successfully! - function 2\",\"input\":{}}",
"headers": {
"X-Powered-By": "AWS Lambda & serverless"
},
"isBase64Encoded": false
}
What if I want the two functions to have different parameters/return type? Is there anything which prevents that?