Skip to content

A serverless AWS Lambda function (in a Docker container) that compiles and executes Java code on demand. Built with TypeScript and Node.js, pre-installed with Java 8. Designed to be triggered via API Gateway.

License

Notifications You must be signed in to change notification settings

makendym/java-lambda-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Lambda Runner

Table of Contents

Description

A serverless application designed to execute Java code within a Node.js environment on AWS Lambda. This project demonstrates a powerful hybrid architecture using TypeScript, Java, and Docker.

This application allows users to send Java code via an API, which is then compiled and executed on the fly. It features:

  • Serverless Architecture: Leverages AWS Lambda to run code without provisioning servers.
  • Hybrid Runtime: A unique combination of a Node.js handler spawning child processes to compile (javac) and run (java) Java code.
  • Containerization: A custom Docker image ensuring consistent runtime environments with both Node.js and Java 8 installed.
  • API Integration: Exposed via API Gateway to handle POST requests with raw Java code.

Sneak-Peek

Architecture Diagram

Getting Started

Prerequisites

  • Node.js (v14+)
  • Docker (for local testing and building)
  • AWS CLI (for deployment)

1. Build the Docker Image

Navigate to the project directory and build the container image:

docker build -t java-lambda-runner .

This creates a local image with both Node.js and Java runtime environments.

2. Run Locally (Optional)

You can test the function locally using the Docker container:

docker run -p 9000:8080 java-lambda-runner

Then send a POST request to http://localhost:9000/2015-03-31/functions/function/invocations.

3. Deploy to AWS

Tag and push the image to AWS ECR, then update your Lambda function to use this new image.

# Example push commands
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com
docker tag java-lambda-runner:latest <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/java-lambda-runner:latest
docker push <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/java-lambda-runner:latest

Contributing

Contributions are always accepted.


What I Learned

Creating this project provided valuable hands-on experience in:

  • Serverless Hybrid Runtimes: orchestrating interactions between Node.js and Java within a single Lambda environment.
  • System Processes: Using Node.js spawnSync to manage file input/output, compilation (javac), and execution (java) safely.
  • Docker Containerization: Building custom multi-language runtime images for AWS Lambda.
  • API Design: Handling dynamic code execution requests and formatting standard output/error responses for the client.
  • Security Awareness: Understanding the implications of remote code execution and the need for sandboxing (container isolation).

Questions?

Developer Profile Picture

For any questions, please contact me with the information below:

Email: <Midouinmakendy@gmail.com>

About

A serverless AWS Lambda function (in a Docker container) that compiles and executes Java code on demand. Built with TypeScript and Node.js, pre-installed with Java 8. Designed to be triggered via API Gateway.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published