I'm using subprocess() on AWS lambda And using this layer: https://github.com/lambci/git-lambda-layer
Here is code:
import json
import os
import subprocess
def lambda_handler(event, context):
os.chdir('/tmp')
subprocess.Popen(["git", "clone", "https:/github.com/hongmingu/requirements"], shell=True)
subprocess.Popen(["touch word.txt"], shell=True)
word = str(subprocess.check_output(["ls"], shell=True))
return {
'statusCode': 200,
'body': json.dumps(word)
}
And it returns:
Response:
{
"statusCode": 200,
"body": "\"b'word.txt\\\\n'\""
}
So there is something wrong on subprocess.Popen(["git", "clone", "https:/github.com/hongmingu/requirements"], shell=True)
I checked there is git by subprocess.check_output(["git --version"], shell=True) and it works well.
How to solve it?
subprocess.Popenis non-blocking. You may want to usesubprocess.run. And btw, If shell isTrue, it is recommended to pass args as a string rather than as a sequence.