AWS Lambda Configuration with Java CDK 📎
public class Greetings{
static String message = System.getenv("message");
public String onEvent(Map<String, String> input) {
System.out.println("configured: " + message);
return message;
}
}
All environment variables are set with the environment
method in the function's Builder
:
Function createUserListenerFunction(String functionName,String functionHandler, int memory, int timeout) {
return Function.Builder.create(this, functionName)
.runtime(Runtime.JAVA_11)
.code(Code.fromAsset("../target/function.jar"))
.handler(functionHandler)
.memorySize(memory)
.environment(Map.of("message","hello, duke"))
.functionName(functionName)
.timeout(Duration.seconds(timeout))
.build();
}
The code above is an excerpt from the following screencast:
The project template used in this screencast is available from: https://github.com/AdamBien/aws-lambda-cdk-plain.