简体   繁体   English

OSError: Errno 30Read-only file system: 我正在尝试使用 Lambda 将一些文件从 FTP 传输到 S3。 该代码适用于笔记本电脑,文件在 S3 中可见

[英]OSError: Errno 30Read-only file system: I am trying to transfer some files from FTP to S3 using Lambda. The code works on laptop, files seen in S3

I tried to use different libraries as s3fs and wrote a new code which also returned the same error.我尝试使用不同的库作为 s3fs 并编写了一个新代码,它也返回了相同的错误。 This code have been working on my laptop fine and I could see the files from FTP server in S3 bucket, but no luck on running on lambda.这段代码在我的笔记本电脑上运行良好,我可以在 S3 存储桶中看到来自 FTP 服务器的文件,但在 lambda 上运行没有运气。 The handler name have been updated in lambda.处理程序名称已在 lambda 中更新。 It looks like something is wrong while trying to download the files itself.尝试下载文件本身时似乎出了点问题。 I am a newbie to coding, especially Python.我是编码新手,尤其是 Python。 Any help or Insights are welcomed.欢迎任何帮助或见解。 The error at lambda execution is: Downloading: on_dth2_tv_sources_v22_20210602.xml.gz [ERROR] OSError: [Errno 30] Read-only file system: 'on_dth2_tv_sources_v22_20210602.xml.gz' Traceback (most recent call last): The error at lambda execution is: Downloading: on_dth2_tv_sources_v22_20210602.xml.gz [ERROR] OSError: [Errno 30] Read-only file system: 'on_dth2_tv_sources_v22_20210602.xml.gz' Traceback (most recent call last):

The code is:代码是:

import boto3 
import os
import ftplib
#FTP HOST AND CREDENTIALS
FTP_HOST = "*******"
FTP_USER = "*****"
FTP_PASS = "*****"

#AWS Bucket
s3 = boto3.resource('s3')
bucket = "*******"
def lambda_handler(event, context):
    Epg_Ftp = ftplib.FTP(FTP_HOST) #Connecting to FTP server
    Epg_Ftp.login(FTP_USER, FTP_PASS) #logging in to FTP
    print(Epg_Ftp.pwd())
    path = "*****" #epg directory
    Epg_Ftp.cwd(path)  #moving to epg directory
    print(Epg_Ftp.pwd())
    filenames = Epg_Ftp.nlst() # get filenames within the directory
    # print(filenames)   
    for file in filenames:
        print(f"\nDownloading : {file}")
        with open(file, "wb") as bfile:
            Epg_Ftp.retrbinary(f"RETR {file}", bfile.write)
            s3.meta.client.upload_file( + file, bucket, file) #uploading to S3
            print(f"File {file} uploaded to S3")
        Epg_Ftp.quit

The problem you're having is that you can't write to the directory that your lambda code is executing in when you do open(file, "wb") .您遇到的问题是,当您执行open(file, "wb")时,您无法写入 lambda 代码正在执行的目录。 Lambda does provide a 500MB temporary disk at /tmp . Lambda 确实在/tmp提供了一个 500MB 的临时磁盘。 So if you change the path for file to be in /tmp it should work.因此,如果您将文件的路径更改为在/tmp中,它应该可以工作。

        with open('/tmp/' + file, "wb") as bfile:

You'll probably also want to delete the files in the loop as well so that you don't use up all the 500MB of disk space.您可能还想删除循环中的文件,以免用完所有 500MB 的磁盘空间。 If any single file is over 500MB, you won't be able to do it this way.如果任何单个文件超过 500MB,您将无法这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 lambda 上使用 simpletransformers 时出现“[ERROR] OSError: [Errno 30] Read-only file system” docker - "[ERROR] OSError: [Errno 30] Read-only file system" when using simpletransformers on lambda docker OSError: [Errno 30] Read-only file system when trying to open PDF in Python Code by Zapier - OSError: [Errno 30] Read-only file system when trying to open PDF in Python Code by Zapier 使用 Lambda 从 S3 上的 CSV 文件在 S3 上创建 zip 文件 - Create a zip file on S3 from CSV files on S3 using Lambda 如何使用 pandas 从 s3 读取文件? - How can I read files from s3 using pandas? 如何使用 Xarray 读取 lambda 中的 S3 文件? - how to read S3 files in lambda using Xarray? 使用 Python 从 S3 将文件上传到 FTP 位置 - Upload Files to FTP location from S3 using Python 从 S3 下载文件时 AWS Lambda 中的错误“只读文件系统” - Error "Read-only file system" in AWS Lambda when downloading a file from S3 Visual Studio代码:OSError:[Errno 30]试图在Linux Mint上安装pylint时的只读文件系统 - Visual Studio Code: OSError: [Errno 30] Read-only file system while trying to install pylint on Linux Mint 每当我向 s3 添加新文件时,如何将文件从 s3 传输到我的 ec2 实例? - How do I transfer files from s3 to my ec2 instance whenever I add a new file to s3? 使用 SFTP 将文件从 AWS S3 传输到 Unix 服务器 - Transfer files from AWS S3 to Unix Server using SFTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM