Java

Server-less Java

Java as cloud-deployed AWS Lambda Functions operating through the AWS API Gateway.


Simple, interactive Java examples collected over the last 10 months or so...

Preparing the Java Function


I'm simplifying here for space but in essence, each Java function here becomes a handler for the receipt of input data to the AWS Lambda. In each instance I have created an input class that deserialises the JSON input {eg. into an int along with an array of ints} as below

That data is processed by the Java function and the result converted to JSON return which is picked up by the front end here.

Deployment on AWS


In brief, the Java handler class is packaged in Maven along with a CloudFormation Stack presented as a .yaml file into a JAR. This comprises the AWS Lambda function which is triggered through the API Gateway which expects corresponsing parameters to the input class via the handler.

I'm also using the AWS Serverless Application Model {SAM} to upload the stack using the AWS CLI.

To simplify front end connection to the API endpoint, API Gateway also provides an SDK. Simply choose your platform as below - I'm using Javascript for my API call here.

Just pop the resulting apigClient.js script and lib folder at the same level as this calling page in your directory structure. Remember to include apigClient.js in the calling script too!