2

I'm trying to incorporate some AWS features into my JSF application. I have multiple EC2 instances running windows server, I would like to know how many windows users are connected to each instance and if they are actively using the system or not.

That info will be further used to create and terminate instances on the fly. I've tried using a ELB, but there is no metric for number of users connected and if they are active or not.

Currently I'm using the Java AWS SDK 1.11.657 due to some application constraints. Given that I have a list of my instances and power to create and terminate them, how would I go about finding the number of users connected to each instance? Did not find anything online using the Java SDK. Thank you.

Alexandre Krabbe
  • 727
  • 1
  • 13
  • 33
  • What does it mean to be connected to a Windows instance? Are you talking about a count of active RDP sessions? You'd use the Remote Desktop Services API/SDK or PowerShell cmdlets for that. – jarmod Oct 29 '19 at 14:42
  • Yes, I'm talking about active RDP sessions. But with only the EC2 instances in hand, without actually connecting via RDP into each of of them am I able to execute cmdlets? Thank you. – Alexandre Krabbe Oct 29 '19 at 14:47
  • 1
    You should be able to use SSM Run Command to run a given PS1 script against a collection of EC2 instances, identified by instance IDs or tags. – jarmod Oct 29 '19 at 15:06
  • Brilliant, I did not know about that. If you could post that as an answer I would gladly accept it. Thank you. – Alexandre Krabbe Oct 29 '19 at 15:14

1 Answers1

1

You can use the Remote Desktop Services API/SDK or PowerShell cmdlet (Get-RDUserSession) to determine the count of active RDP sessions. There's also, allegedly, a more sophisticated cross-server PowerShell script.

To remotely invoke PowerShell scripts on Windows instances, you can use SSM Run Command. Here's an example of using the awscli to do this:

aws ssm send-command \
    --document-name "AWS-RunShellScript" \
    --comment "List Windows services" \
    --instance-ids "i-1234567890,i-0987654321" \
    --parameters commands="service --status-all" \
    --output text

Note that your Windows instances need to be set up in advance to support this so see this tutorial. It's likely Linux-oriented but hopefully this gets you started in the right direction.

jarmod
  • 71,565
  • 16
  • 115
  • 122