1

I'd like to call a python function from within a Google cloud function like so:

  `shell.exec(`${PYTHON_FUNCTION} parameters`, function(code, stdout, stderr) {`

Is this possible? And if so how would I do it?

Thank you very much

5
  • 1) What research have you done? Did you try your example? What was the result? 2) Cloud Functions is a lightweight serverless platform for event-driven code. It is not an operating system and does not provide most features of an OS. 3) The function shell.exec would require the Python program, libraries, and environment to run a Python function. The Cloud Functions node.js environment does not include Python. Commented Mar 9, 2021 at 20:34
  • Thanks for your reply. From my research, the function runs on ubuntu-18-04 which does have Python installed so I was thinking I can call Python from the function. Basically, I think I'm missing the correct location of the Python binary. Commented Mar 9, 2021 at 22:50
  • 1
    Cloud Functions run in a container and not directly within the host Ubuntu operating system. Functions are isolated. The node.js environment does not include Python. Commented Mar 9, 2021 at 23:22
  • Thanks, I guess that isn't going to work then :( Commented Mar 10, 2021 at 0:01
  • @JohnHanley your comment is very helpful. Please post it as an answer. Commented Mar 10, 2021 at 6:59

1 Answer 1

3

Cloud Functions code runs inside a container that is set up for specific environments. For example, in your question, you are using the Node.js execution environment.

Your goal is to call a Python function (script) from Node.js. This would require the Python interpreter, libraries, and a correctly set up environment.

The Cloud Functions Node.js execution environment does not include the Python execution environment. Therefore the answer is not possible using Google provided execution environments.

If you would like to combine Node.js and Python, I recommend creating a custom Cloud Run container and deploying to Cloud Run, which is the big brother to Cloud Functions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.