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.
- 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.
RemoteExecutorApplication.java: Spring Boot entry point.AsyncConfig.java: enables@Asyncprocessing.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.
-
Submit an execution
ExecutionController#submitExecutionreceives{ command, instanceType }and callsExecutionService#submitExecution. -
Create an execution (in memory)
ExecutionService#submitExecutioncreates anExecution, assigns an ID, setsQUEUED, and stores it in an in-memory map. -
Process asynchronously
ExecutionService#processExecutionruns in the background (@Async) and updates the execution status throughout the lifecycle. -
Start EC2 + wait for public IP
Ec2ProvisioningService#startInstancelaunches EC2 andEc2ProvisioningService#waitForPublicIppolls until the instance is running and has a public IP. -
Execute command over SSH
SshExecutionService#executeCommandconnects via SSH, executes the command, and captures stdout/stderr + exit code. -
Store result + terminate EC2
On success the execution becomesFINISHEDand stores output; on error it becomesFAILEDand stores the error message. In both cases the EC2 instance is terminated infinally.
Update src/main/resources/application.properties with your AWS/EC2/SSH settings.
- Start the application:
mvn spring-boot:run- Submit a command (API base URL:
http://localhost:8080). Example withcurl:
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}.