MicroProfile on Quarkus on AWS Lambda on Java / JVM (Amazon Corretto): ARM vs. Intel 📎
public class CDKStack extends Stack {
static String FUNCTION_BASE_NAME = "airhacks_Greetings";
static String lambdaHandler = "io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest";
static int memory = 512;
public CDKStack(Construct scope, String id, boolean httpAPIGatewayIntegration) {
super(scope, id);
var functionName = FUNCTION_BASE_NAME + "Intel";
var intelFunction = createFunction(functionName, lambdaHandler, Architecture.X86_64,memory,"hello, intel");
integrateWithHTTPApiGateway(functionName,intelFunction);
functionName = FUNCTION_BASE_NAME + "ARM";
var armFunction = createFunction(functionName, lambdaHandler, Architecture.ARM_64, memory,"hello, graviton");
integrateWithHTTPApiGateway(functionName,armFunction);
}
void integrateWithHTTPApiGateway(String functionName,Function function){
var lambdaIntegration = HttpLambdaIntegration.Builder.create(functionName+"HttpApiIntegration",function).build();
var httpApiGateway = HttpApi.Builder.create(this, functionName+"HttpApiIntegration").defaultIntegration(lambdaIntegration).build();
CfnOutput.Builder.create(this, functionName+"HttpApiIntegrationOutput").value(httpApiGateway.getUrl()+"hello").build();
}
Function createFunction(String functionName,String functionHandler, Architecture architecture,int memory,String message) {
var configuration = Map.of("message",message);
return Function.Builder.create(this, functionName)
.runtime(Runtime.JAVA_11)
.architecture(architecture)
.environment(configuration)
.code(Code.fromAsset("../lambda/target/function.zip"))
.handler(functionHandler)
.memorySize(memory)
.functionName(functionName)
.build();
}
}
The ARM configuration is a bit faster and costs less:
The MicroProfile on Quarkus as AWS Lambda quickstarter is available from github.com/AdamBien/aws-quarkus-lambda-cdk-plain.