Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

amazon ec2 - Running shell script on already running AWS ec2 instance from java

I have an ec2 instance already running in AWS cloud. My objective is to execute a shell script on this running ec2 instance from my java program.

So far I have been not able to get much code examples or documentation for same. I understand that I first need to get hold of AmazonEC2Client as:

AWSCredentials credentials = new BasicAWSCredentials(accessKey,accessSecret);
AmazonEC2Client ec2 = new AmazonEC2Client(credentials);

What should be my further approach to achieve my objective?

question from:https://stackoverflow.com/questions/65871000/running-shell-script-on-already-running-aws-ec2-instance-from-java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I guess your EC2 will need to expose an endpoint API for this to happen.

You might want to write another script using a high-level language (Python or Node.js are excellent examples with great Web-Api support), where this new script listens to a certain port number, and executes your underlying shell script upon request.

This would give you some flexibility in securing your endpoint if you wish, externally monitoring your script, and having any sort of statistical analysis on the request.

Another option would be to extend your original shell script to act as a server itself. Ex.

while { echo -en "Received Request"; } | nc -l "${1:-8080}"; do

However this is less flexible with more room for security vulnerabilities.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...