当我尝试在 AWS Lambda 函数 (python) 中使用 bash 脚本创建文件时出现错误 "read only file system"
error "read only file system" when I'm trying to create file using bash script in AWS Lambda function (python)
我有 python (3.8) Lambda 函数连接到 EFS,挂载 /mnt/my-mount
。
我想通过函数 运行 一个 bash 脚本,所以我创建了另一个文件 script.sh
.
这是python函数:
import json
import os
def lambda_handler(event, context):
os.system("sh script.sh")
和bash脚本script.sh
:
#!/bin/bash
touch hello.txt
我收到以下错误:
cannot touch script.sh: Read-only file system
备注:
- 我可以使用 python 函数创建文件 (f.write)。
- 如果我 运行
os.system("chmod 777 a.sh")
,我又得到 Read-Only file system
。
- 如果我使用
rc = subprocess.call("bash a.sh")
,我会得到 No such file or directory: 'bash a.sh'
- EFS 为具有
777
权限的用户 1000:1000
提供访问点。
这可能是因为 Lambda 角色没有适当的写入权限。您应该附加适当的政策或定义您的自定义政策:
我有 python (3.8) Lambda 函数连接到 EFS,挂载 /mnt/my-mount
。
我想通过函数 运行 一个 bash 脚本,所以我创建了另一个文件 script.sh
.
这是python函数:
import json
import os
def lambda_handler(event, context):
os.system("sh script.sh")
和bash脚本script.sh
:
#!/bin/bash
touch hello.txt
我收到以下错误:
cannot touch script.sh: Read-only file system
备注:
- 我可以使用 python 函数创建文件 (f.write)。
- 如果我 运行
os.system("chmod 777 a.sh")
,我又得到Read-Only file system
。 - 如果我使用
rc = subprocess.call("bash a.sh")
,我会得到No such file or directory: 'bash a.sh'
- EFS 为具有
777
权限的用户1000:1000
提供访问点。
这可能是因为 Lambda 角色没有适当的写入权限。您应该附加适当的政策或定义您的自定义政策: