How to get user count on a EC2 Windows Instance AWS - java

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.

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.

Related

how to login and create file in ec2 using java code

I have aws ec2 instance, i need to connect to ec2 and create script and run the script in ec2 using java,can any one help me.
thanks in advance.
In order to connect to ec2 instance you can use ssh.
If ec2 instance is in private subnet you will have to connect to it using bastion instance, otherwise you can connect directly using public ip address.
After you connected using ssh you can write whatewer script you want, or just copy it directly using scp.
In order to run java program make sure java is installed in your instance (run java -version command). If it is not installed you will have to install jvm first. The commands will be different depending on OS of your instance. Most probably it should be CentOS or Ubuntu.
After java is installed use java -jar jarfilename.jar command to run your application.

How to execute a CMD command on multiple EC2 Windows instance?

Till now I was able to launch multiple EC2 Windows instance & get its parameters (password / IP) with aws-api-tool .
Now I'd like to find a way to execute the selenium grid command on all those instances. Is it possible to do this with automation?
If any one can give me a sample program for this, that would be helpful.
I am running Windows server 2008 on all those instances.
The Amazon EC2 Systems Manager Run Command can run commands on multiple Amazon EC2 instances.
It requires installation of an agent. Commands can then be run via the Management Console, AWS Command-Line Interface (CLI) or API calls.

Configurate Spark by given Cluster

I have to send some applications in python to a Apache Spark cluster. There is given a Clustermanager and some worker nodes with the addresses to send the Application to.
My question is, how to setup and to configure Spark on my local computer to send those requests with the data to be worked out to the cluster?
I am working on Ubuntu 16.xx and already installed java and scala. I have searched the inet but the most find is how to build the cluster or some old advices how to do it, which are out of date.
i assume you remote cluster is running and you are able to submit jobs on it from remote server itself. what you need is ssh tuneling. Keep in mind that it does not work with aws.
ssh -f user#personal-server.com -L 2000:personal-server.com:7077 -N
read more here: http://www.revsys.com/writings/quicktips/ssh-tunnel.html
your question is unclear. If the data are on your local machine, you should first copy your data to the cluster on HDFS filesystem. Spark can works in 3 modes with YARN (are u using YARN or MESOS ?): cluster, client and standalone. What you are looking for is client-mode or cluster mode. But if you want to start the application from your local machine, use client-mode. If you have an SSH access, you are free to use both.
The simplest way is to copy your code directly on the cluster if it is properly configured then start the application with the ./spark-submit script, providing the class to use as an argument. It works with python script and java/scala classes (I only use python so I don't really know)

Is it possible to run java command line app from python in AWS EC2?

I am working on some machine learning for chemical modelling in python. I need to run a java app (from command line through python subprocess.call) and a python webserver. Is this possible on AWS EC2?
I currently have this setup running on my mac but I am curious on how to set it up on aws.
Thanks in advance!
Since you're just making a command line call to the Java app, the path of least resistance would just be to make that call from another server using ssh. You can easily adapt the command you've been using with subprocess.call to use ssh -- more or less, subprocess.call(['ssh', '{user}#{server}', command]) (although have fun figuring out the quotation marks). As an aside on those lines, I usually find using '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' stabilizes scripted SSH calls in my environment.
The more involved thing will be setting up the environments to properly run the components you need. You'll need to set up ssh configs so that your django app can ssh over and set up -- probably with private key verification. Then, you'll need to make sure that your EC2 security groups are set up to allow the ssh access to your java server on port 22, where sshd listens by default.
None of this is that hairy, but all the same, it might be stabler to just wrap your Java service in a HTTP server that your Django app can hit. Anyway, hope this is helpful.

how to execute a shell script and get back his result from a windows station with java?

i'm trying to execute a shell script from a j2ee application (made with flash builder 3, spring, apache cxf) et get the result of its execution in my flex interface.
the problem is my application is on a windows 7 station and i don't know how i can execute the script on a distant unix server & get back the result.
i know that ssh apis can help but i've no idea how to get back the result.
any help will be welcome.
thanx
If you have ssh installed on your windows machine, you should be able to execute a command like
ssh user#remote_host ipconfig
This will execute ipconfig on the remote_host as user "user". You will need to do a bit of research into ssh so that you can make it so you can log in without using a password, but google will help with that.
Alternatively you could look in to a java implementation of ssh - jssh for example, although I confess that I have no experience of using that package.
To execute program from windows to unix you really need ssh or telnet.
SSH is more secure. You can do this without running external process. Use one of available pure java SSH libraries (e.g. javassh.org).
See examples. If you use this library your task is trivial. Just call appropriate API.
About the only reasonable and reasonably secure answer I could come up with is to configure ssh on both machines.
*nix boxes usually have ssh server installed by default.
Putty terminal emulation for windows comes with neat ssh client command line utility called plink which can execute shell commands on a remote unix box in a secure manner.

Categories

Resources