我只是想通过lambda触发一个示例java程序。 所以我在/ src / main / java的com.amazonaws.lambda包中创建了两个类,它们是LambdaFunctionHandler.java和MessageService.java。
package com.amazonaws.lambda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
@Component
public class LambdaFunctionHandler implements RequestHandler<Object, String>
{
@Autowired
private MessageService messsageService;
public String handleRequest(Object input, Context context) {
return messsageService.getMessage();
}
}
第二节是
package com.amazonaws.lambda;
public class MessageService {
public String getMessage() {
return "hello world";
}
}
我在S3存储桶上传jar文件并从lambda触发它然后得到以下错误:
{
"errorMessage": "java.lang.NullPointerException",
"errorType": "java.lang.NullPointerException",
"stackTrace":
[
"com.amazonaws.lambda.autorfexecution.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:16)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
]
}
TextContext.java
package com.amazonaws.lambda;
import com.amazonaws.services.lambda.runtime.ClientContext;
import com.amazonaws.services.lambda.runtime.CognitoIdentity;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
public class TestContext implements Context {
private String awsRequestId = "EXAMPLE";
private ClientContext clientContext;
private String functionName = "EXAMPLE";
private CognitoIdentity identity;
private String logGroupName = "EXAMPLE";
private String logStreamName = "EXAMPLE";
private LambdaLogger logger = new TestLogger();
private int memoryLimitInMB = 128;
private int remainingTimeInMillis = 15000;
private String functionVersion = "EXAMPLE";
private String invokedFunctionArn = "EXAMPLE";
@Override
public String getAwsRequestId() {
return awsRequestId;
}
public void setAwsRequestId(String value) {
awsRequestId = value;
}
@Override
public ClientContext getClientContext() {
return clientContext;
}
public void setClientContext(ClientContext value) {
clientContext = value;
}
@Override
public String getFunctionName() {
return functionName;
}
public void setFunctionName(String value) {
functionName = value;
}
@Override
public CognitoIdentity getIdentity() {
return identity;
}
public void setIdentity(CognitoIdentity value) {
identity = value;
}
@Override
public String getLogGroupName() {
return logGroupName;
}
public void setLogGroupName(String value) {
logGroupName = value;
}
@Override
public String getLogStreamName() {
return logStreamName;
}
public void setLogStreamName(String value) {
logStreamName = value;
}
@Override
public LambdaLogger getLogger() {
return logger;
}
public void setLogger(LambdaLogger value) {
logger = value;
}
@Override
public int getMemoryLimitInMB() {
return memoryLimitInMB;
}
public void setMemoryLimitInMB(int value) {
memoryLimitInMB = value;
}
@Override
public int getRemainingTimeInMillis() {
return remainingTimeInMillis;
}
public void setRemainingTimeInMillis(int value) {
remainingTimeInMillis = value;
}
@Override
public String getFunctionVersion() {
return functionVersion;
}
public void setFunctionVersion(String value) {
functionVersion = value;
}
@Override
public String getInvokedFunctionArn() {
return invokedFunctionArn;
}
public void setInvokedFunctionArn(String value) {
invokedFunctionArn = value;
}
/**
* A simple {@code LambdaLogger} that prints everything to stderr.
*/
private static class TestLogger implements LambdaLogger {
@Override
public void log(String message) {
System.err.println(message);
}
}
}
所以任何人都可以指导我这里缺少的东西。