简体   繁体   中英

How to run python script from java ee web application in aws elastic beanstalk?

I am working on a java ee application that makes some api calls and passes the result of those api calls to a script in the form of a json file. Locally, my application works just fine but when i try to test it on AWS Elastic Beanstalk, my project doesn't run the python script at all.

While deploying my web application on i have selected as my platform and uploaded my .war file.

Since my project is a simple one, i have left rest of the configurations as they were.

In my code, I and creating a runtime process which calls a bash script which in turn runs the python script.
My bash script is as:
#!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" python $DIR/json_to_matches.py $DIR/output.json

I have included a print("Running python script") statement in the beginning of my python script for debugging purpose.

The screenshot of my local output is:
在此处输入图片说明

But when i deploy my app and test it, my logs show that python script wasn't hit at all.

在此处输入图片说明

I have checked my webroot directories on eb cli and my output.json file is being created by the project, so I don't think it's the issues of output.json file not being found or read/write permissions.

However, I am new to AWS-EB and i may be doing something wrong while deploying my app. I am not sure. Does anyone have any idea how i can run python scripts from my Java EE web application in aws-eb environment?

try running using the Runtime class.

 Process p = Runtime.getRuntime().exec("python example.py");

if python is not in your PATH variable use the address of python install directory as

 Runtime.getRuntime().exec("/usr/local/bin/python example.py")

You can read the output of the command as below:

        BufferedReader stdInput = new BufferedReader(new 
             InputStreamReader(p.getInputStream()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM