【问题标题】: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 S3OSError: Errno 30Read-only file system: 我正在尝试使用 Lambda 将一些文件从 FTP 传输到 S3。该代码适用于笔记本电脑,文件在 S3 中可见
【发布时间】:2021-06-03 19:43:21
【问题描述】:

我尝试使用不同的库作为 s3fs 并编写了一个新代码,它也返回了相同的错误。这段代码在我的笔记本电脑上运行良好,我可以在 S3 存储桶中看到来自 FTP 服务器的文件,但在 lambda 上运行没有运气。处理程序名称已在 lambda 中更新。尝试下载文件本身时似乎出了点问题。 我是编码新手,尤其是 Python。欢迎任何帮助或见解。 lambda 执行时的错误是: 下载:on_dth2_tv_sources_v22_20210602.xml.gz [错误] OSError:[Errno 30] 只读文件系统:'on_dth2_tv_sources_v22_20210602.xml.gz' Traceback(最近一次调用最后一次):

代码是:

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

【问题讨论】:

    标签: python amazon-web-services amazon-s3 aws-lambda ftp


    【解决方案1】:

    您遇到的问题是当您执行open(file, "wb") 时,您无法写入执行 lambda 代码的目录。 Lambda 确实在/tmp 提供了一个 500MB 的临时磁盘。因此,如果您将文件的路径更改为/tmp,它应该可以工作。

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

    您可能还想删除循环中的文件,以免用完所有 500MB 的磁盘空间。如果任何单个文件超过 500MB,您将无法这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      相关资源
      最近更新 更多