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.
- Node.js (v14+)
- Docker (for local testing and building)
- AWS CLI (for deployment)
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.
You can test the function locally using the Docker container:
docker run -p 9000:8080 java-lambda-runnerThen send a POST request to http://localhost:9000/2015-03-31/functions/function/invocations.
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:latestContributions are always accepted.
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
spawnSyncto 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).
For any questions, please contact me with the information below:
Email: <Midouinmakendy@gmail.com>
