On Wed, Jul 24, 2019 at 3:26 PM John Lemon <[email protected]> wrote:

> > Can you explain at a little bit higher level what you're trying to
> accomplish?  Spin up a cloud resource (e.g. EC2 instance) when someone logs
> in, and spin it down when they log out?  Or
> > something else?  Can you share the code you've written so far - is it on
> GitHub somewhere?
>
> Yes, my aim was to spin up EC2 instances only when someone 'selects' the
> connection for them. As users will have multiple options, I don't want all
> instances to be started when a user logs in. And then closed on exit (if no
> one else is using that instance)
>

Okay.  This still should be doable; however, note that there's going to be
some delay between the user clicking on the connection and when it actually
connects due to the time it takes the instance to get started.  You'll need
to handle this somehow - but more on that below.


>
> I've only been playing with the simple code given in the doc's for
> handling a tunnel connection event. So what I did was the below.  But the
> 'Active connections' array is empty and 'Connections Directory' contains
> the list of all connections that user has access to. But I can find no
> other way to find information on the currently selected connection. I took
> a closer look at where the tunnelconnectionevent is called and I see the
> currently selected connection is not passed to the listener (is that
> right?). If that’s the case , that I can't do what I was hoping to do. (I
> hope I'm missing something?)
>
>
The event listener may not be the best way to go, for a couple of reasons.
First, as you point out, working backward from there to the actual
connection is a bit difficult.  Perhaps there's some room for us to improve
that a bit, as it seems like it might be useful to easily get to the
connection that started it from the event itself, but that's a slightly
separate topic.

However, beyond that, I think you're going to hit a timing issue, here,
with the event listeners and what you're trying to accomplish.  That is,
you want the user to click on a connection, have Guacamole go to EC2 and
start an instance, wait for that instance to boot up and become available,
and then connect.  My experience with EC2 is that the booting takes
anywhere between several seconds and a couple of minutes, and I suspect
that you're going to see connection timeouts from Guacamole, even if you
are able to trigger the start at the time it is connected.  You're going to
need to insert some delay into that tunnel connection process such that it
will start the EC2 instance, wait for confirmation that it's available, and
then make the connection - or, at the very least, start the EC2 instance
and retry X number of times every Y seconds.

I suspect that a custom authentication extension might be a better way to
go, because:
- You can dynamically generate the connection list via AWS's Java SDK
- You can override the tunnel implementation such that it either waits
until the instance is available and then connects, or does some retrying
until it succeeds.
- You'll have an easier time finding the connection the user clicked on in
this process because you'll be able to control the process along the way,
inserting bits of code where you need them, rather than just trying to
react to the process (as the event listener does).

-Nick

Reply via email to