Microservice built with TypeScript-based AWS Lambda function that provides Java execution capabilities within a serverless environment. Combines Node.js and Java to create a flexible serverless solution with Docker containerization, API Gateway integration for compiling and running Java code via HTTP requests.
- TypeScript-based AWS Lambda function
- Java 8 runtime support
- Docker containerization for consistent deployment
- UUID generation capabilities
- AWS Lambda integration
- REST API endpoint for Java code execution
- CORS support for web-based clients
- Node.js (v14.17 or higher)
- npm (Node Package Manager)
- Docker (for local testing)
- AWS CLI (for deployment)
- Java 8 (for local development)
- Clone the repository:
git clone https://github.com/makendym/java-lambda-runner.git
cd java-lambda-runner
- Install dependencies:
npm install
- Build the project:
npm run build
The project is written in TypeScript and uses the following main dependencies:
@types/aws-lambda
: TypeScript definitions for AWS Lambdauuid
: For generating unique identifierstypescript
: For TypeScript compilation
The project includes a Dockerfile that:
- Uses AWS Lambda Node.js 22 base image
- Installs Java 8 (Amazon Corretto)
- Sets up the necessary environment for running Java code
- Builds and packages the TypeScript code
To build the Docker image:
docker build -t java-lambda-runner .
- Deploy the Lambda function to AWS using the provided Docker image
- Create an API Gateway REST API and integrate it with the Lambda function
- Configure CORS in API Gateway to allow web-based clients to access the endpoint
The function is configured to use the handler in dist/handler.js
.
The API endpoint accepts POST requests with Java code in the request body. Here's an example using curl:
curl -X POST \
https://your-api-gateway-url/execute \
-H 'Content-Type: application/json' \
-d '{
"code": "System.out.println(\"Hello, World!\");"
}'
You can also send complete Java classes:
curl -X POST \
https://your-api-gateway-url/execute \
-H 'Content-Type: application/json' \
-d '{
"code": "public class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }"
}'
The API will return a JSON response with the following structure:
{
"output": "Program output here",
"error": "Error message if any"
}
java-lambda-runner/
├── src/ # TypeScript source files
├── dist/ # Compiled JavaScript files
├── Dockerfile # Docker configuration
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── .gitignore # Git ignore rules
- The API endpoint is public and should be secured appropriately in production
- Consider implementing rate limiting to prevent abuse
- Monitor Lambda execution times and memory usage
- Set appropriate timeouts for long-running Java programs
This project is licensed under the terms of the included LICENSE file.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request