OOD Ephemeral EC2 Instance - Interactive App

I have an in development interactive app that provisions an ephemeral AWS EC2 instance and then proxies shell access to that instance back through our OOD node.

I can launch the EC2 via a script.sh.erb and wait while it provisions. I can then get shell access at the https://ood.head.node/pun/sys/shell/ssh/xx.xx.xx.xx URL. So, the ssh key setup that was needed and the reverse proxy are working as expected (many thanks for the great documentation on proxying the connection).

Ideally, I would love to have the interactive app have a connect button that initiates the shell session and a stop/delete button wired to shutdown or terminate the EC2 instance. To accomplish this, should I be writing an info.html.erb and then polling the job status and providing a connection link to users or is there a built-in approach that I have missed in the docs? Can the after.sh then store the teardown code? (As it is working currently, after.sh executes as soon as script.sh.erb finishes so the EC2 is immediately torn down.)

Many thanks!

My submit.yml looks like this:

---
shell:
  conn_params:
      - private_ip
script:
  job_name: "EC2"

and the script.sh.erb looks like this:

---
# Ensure output directory exists

OOD_DASHBOARD_HOST=$(hostname -I | awk '{print $1}')

while ! nc -z ${private_ip} 22; do
  sleep 5
  echo "Still waiting for ssh"
done

echo "SSHing to ${USER}@${private_ip}:22"
OUTPUT_DIR="${OOD_BC_JOB_OUTPUT_DIR:-$OLDPWD}"
mkdir -p "$OUTPUT_DIR"
echo "outdir: ${OUTPUT_DIR}"

# Write connection.yml for Open OnDemand
cat <<EOL > "$OUTPUT_DIR/connection.yml"
---
host: "${private_ip}"
port: 22
EOL

echo "Connection file created at: $OUTPUT_DIR/connection.yml"

echo "SSH is now available. Launching shell session..."

# Execute SSH session through OnDemand's reverse proxy
echo "Opening connection via https://${OOD_DASHBOARD_HOST}/node/${private_ip}/22"

What adapter are you using here to launch this? I don’t know if there’s an easy way to do this without some adapter support. You could put a button in info.html.erb but there’s no easy way to make that button do actions on the server without hacking all sorts of stuff (also thankfully a link to the terminal/ssh application won’t execute commands for you for security reasons).

It could be worth while to hack together an ec2 adapter and use it. Here’s an example of how I’ve hacked together a localhost adapter for a demo container:

Full file here at the current commit:

All files here to view:

That said - I’d also look into Slurm’s ability to launch ec2 instances itself. This way you interact with Slurm like you always would, and let it do the heavy lifting. That’s if you have Slurm anyhow (or want to create a cluster in AWS).