![](/img/trans.png)
[英]Permission denied after uploading AWS Lambda python zip from S3
[英]call python from nodejs on AWS lambda - permission denied
我可以使用下面的函數從AWS Lambda上的nodejs調用我的python。 但是,因為我需要特定的python庫,所以我在env目錄中創建了一個virutalenv。 我把所有東西拉上拉鏈然后推到Lambda。 但是當我嘗試從虛擬目錄調用python時,我得到一個Permission Denied錯誤。
我試圖在調用python之前修改Lambda上的chmod權限,但是得到了Operation Not Permitted。 我怎么能讓它運行?
console.log('Loading event');
var exec = require('child_process').exec;
exports.handler = function(event, context) {
exec('env/bin/python district.py \'' + JSON.stringify(event) + '\'', function(error, stdout) {
var obj = stdout.toString();
context.done(error, obj);
});
};
這是錯誤:
{
"errorMessage": "Command failed: /bin/sh: env/bin/python: Permission denied\n",
"errorType": "Error",
"stackTrace": [
"",
"ChildProcess.exithandler (child_process.js:658:15)",
"ChildProcess.emit (events.js:98:17)",
"maybeClose (child_process.js:766:16)",
"Process.ChildProcess._handle.onexit (child_process.js:833:5)"
]
}
試試這個:
exec('python district.py "'+ JSON.stringify(event) +'"', function(error, stdout) {
console.log('Python returned: ' + stdout + '.');
context.done(error, stdout);
});
亞馬遜在LAMBDA使用Python的教程在這里
該錯誤很可能表明python.exe
沒有設置可執行位。 但請注意,即使您設置了x位,它也不起作用: .exe
文件是Windows可執行文件,它們將無法工作。
注意,這個虛擬環境是在windows中創建的。 我也嘗試從
env/bin/python district.py
沒有幫助的env/bin/python district.py
中的Linux。
env/bin/python
是正確的命令。 如果仍然出現Permission Denied錯誤,則表示文件python
缺少可執行位。
在AWS Lamba運行時環境中,不允許更改文件的權限,也不允許更改用戶,因此在創建.zip存檔時 必須設置可執行位 (或任何其他權限位)。
總結一下:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.