无法通过 Lambda 函数创建 ZIP 文件
Not able to create ZIP file through Lambda function
我有一个小的 lambda 函数,它从 s3 存储桶中下载文件,创建它的 zip 并再次上传到 S3 存储桶。
我的lambda函数使用.net core3.1.
我可以写文本文件,但不能创建 zip 文件。
C# 中的 Zip 文件代码(因为它部署在 linux 系统中,因此我尝试在 Tmp 目录中创建 zip 文件)
ZipFile.CreateFromDirectory(@"/tmp/", "test.zip");
Lambda 函数 return 低于错误。
Error :
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.CreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName)
at XXX.DownloadService.CreateZip(DownloadRequest downloadRequest) in D:\Projects\DownloadService.cs:line 133
我不知道我做错了什么。或者如果这种方法是错误的,可以用什么替代创建 zip 文件。
帮帮我。
提前致谢。
我怀疑它试图在 read-only 目录中创建 Zip 文件。第二个参数可以包含目标 Zip 文件的路径:
public static void CreateFromDirectory (string sourceDirectoryName, string destinationArchiveFileName);
destinationArchiveFileName
: The path of the archive to be created, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.
但是,在 AWS Lambda 函数中,只能写入 /tmp/
目录。这可能与您正在压缩整个 /tmp/
目录这一事实相冲突。您可能需要将文件放在 /tmp/
目录的 sub-directory 中:
ZipFile.CreateFromDirectory(@"/tmp/files_to_zip/", "/tmp/test.zip");
我有一个小的 lambda 函数,它从 s3 存储桶中下载文件,创建它的 zip 并再次上传到 S3 存储桶。
我的lambda函数使用.net core3.1.
我可以写文本文件,但不能创建 zip 文件。
C# 中的 Zip 文件代码(因为它部署在 linux 系统中,因此我尝试在 Tmp 目录中创建 zip 文件)
ZipFile.CreateFromDirectory(@"/tmp/", "test.zip");
Lambda 函数 return 低于错误。
Error :
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.DoCreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName, Nullable`1 compressionLevel, Boolean includeBaseDirectory, Encoding entryNameEncoding)
at System.IO.Compression.ZipFile.CreateFromDirectory(String sourceDirectoryName, String destinationArchiveFileName)
at XXX.DownloadService.CreateZip(DownloadRequest downloadRequest) in D:\Projects\DownloadService.cs:line 133
我不知道我做错了什么。或者如果这种方法是错误的,可以用什么替代创建 zip 文件。
帮帮我。
提前致谢。
我怀疑它试图在 read-only 目录中创建 Zip 文件。第二个参数可以包含目标 Zip 文件的路径:
public static void CreateFromDirectory (string sourceDirectoryName, string destinationArchiveFileName);
destinationArchiveFileName
: The path of the archive to be created, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.
但是,在 AWS Lambda 函数中,只能写入 /tmp/
目录。这可能与您正在压缩整个 /tmp/
目录这一事实相冲突。您可能需要将文件放在 /tmp/
目录的 sub-directory 中:
ZipFile.CreateFromDirectory(@"/tmp/files_to_zip/", "/tmp/test.zip");