Skip to content

Crenwuste/AWS-Remote-Executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remote Executor (Spring Boot + AWS EC2)

This project is a Spring Boot REST API that runs a shell command on a temporary AWS EC2 instance via SSH, stores the execution state in memory, and terminates the instance at the end.

Features

  • REST API: submit an execution and query its status/results.
  • In-memory storage: executions are stored in a thread-safe ConcurrentHashMap.
  • Async processing: the request returns quickly while the EC2/SSH work runs in the background (@Async).
  • EC2 lifecycle management: start instance, wait for public IP, terminate instance.
  • SSH execution: run a single command and capture stdout/stderr + exit code.

Project Structure

  • RemoteExecutorApplication.java: Spring Boot entry point.
  • AsyncConfig.java: enables @Async processing.
  • controller/ExecutionController.java: REST endpoints (/executions).
  • service/ExecutionService.java: orchestrates the whole flow (create execution, call EC2 + SSH, update status).
  • service/Ec2ProvisioningService.java: EC2 start -> wait for public IP -> terminate.
  • service/SshExecutionService.java: SSH connect + execute command (JSch).
  • model/Execution.java: execution model (in-memory).
  • model/ExecutionStatus.java: QUEUED, IN_PROGRESS, FINISHED, FAILED.
  • dto/ExecutionRequest.java: request payload for submitting executions.

How It Works

  1. Submit an execution
    ExecutionController#submitExecution receives { command, instanceType } and calls ExecutionService#submitExecution.

  2. Create an execution (in memory)
    ExecutionService#submitExecution creates an Execution, assigns an ID, sets QUEUED, and stores it in an in-memory map.

  3. Process asynchronously
    ExecutionService#processExecution runs in the background (@Async) and updates the execution status throughout the lifecycle.

  4. Start EC2 + wait for public IP
    Ec2ProvisioningService#startInstance launches EC2 and Ec2ProvisioningService#waitForPublicIp polls until the instance is running and has a public IP.

  5. Execute command over SSH
    SshExecutionService#executeCommand connects via SSH, executes the command, and captures stdout/stderr + exit code.

  6. Store result + terminate EC2
    On success the execution becomes FINISHED and stores output; on error it becomes FAILED and stores the error message. In both cases the EC2 instance is terminated in finally.

Configuration

Update src/main/resources/application.properties with your AWS/EC2/SSH settings.

Run locally

  1. Start the application:
mvn spring-boot:run
  1. Submit a command (API base URL: http://localhost:8080). Example with curl:
curl -X POST http://localhost:8080/executions \
  -H "Content-Type: application/json" \
  -d '{"command": "echo hello world", "instanceType": "t3.micro"}'

The response includes the execution id. To check status or output, use GET /executions/{id}.

About

Remote Executor is a Spring Boot REST API that asynchronously provisions a temporary AWS EC2 instance, runs a shell command over SSH, stores execution state in memory, and terminates the instance after completion. It provides simple endpoints to submit executions and retrieve status/results.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages