1

Embarked on aws lambda platform, attempted running python sub process function for invoking php url, which did not yield the desired outcome. Here given below the code for your ready reference:

import json
import subprocess

# if the script don't need output.

subprocess.call('php https://mbracecloud.com/post_form.php', stdin=None, stdout=None, stderr=None, shell=False)

On running this code, we encounter this error:

"errorMessage": "[Errno 2] No such file or directory: 'php https://mbracecloud.com/post_form.php'",
  "errorType": "FileNotFoundError",

Though the file exists, it is displaying error "file not found"

Edit:

Okay based on what maurice said, followed the new code of python standard library from another thread. Ran the code below:

import requests
r = requests.post("http://bugs.python.org", data={'number': 12524, 'type': 'issue', 'action': 'show'})
print(r.status_code, r.reason)

There seems to some problem with import "request". How do i overcome this ?

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
  "errorType": "Runtime.ImportModuleError"
}
  • PHP expects a path, not a url. –  Dec 24 '20 at 11:20
  • Does this answer your question? [encountered "sh: php: command not found" error while running os.system module in lambda](https://stackoverflow.com/questions/65445455/encountered-sh-php-command-not-found-error-while-running-os-system-module-in) – Jens Dec 25 '20 at 13:46

1 Answers1

0

What you're telling the python interpreter to do is running the command php https://... in your Lambda Runtime Environment. Unless you're using a custom runtime, php won't be installed in the Lambda Execution Context. That's why it results in a FileNotFoundError when you try to execute php.

I assume what you're actually trying to do is call the API behind the URL you mention, for that you can use the python standard library. This answer has an example for that.

Maurice
  • 11,482
  • 2
  • 25
  • 45
  • Thanks for the reply. Please take a look at the edited answer. – husaindevelop Dec 24 '20 at 12:27
  • @husaindevelop The edit is actually a different question. Please create a new question for it on the site and feel free to accept my answer if it helped you. I specifically linked to the answer that uses the Python Standard library. The requests module is easier to use, but needs to be installed and deployed to lambda first - again this is a different question, which probably has been asked here a few times ;-) – Maurice Dec 24 '20 at 22:51