[英]AmazonS3Client does not work in AWS Lambda S3 Project
I have a simple C# console project that it is working with S3 Bucket and s3 objects. 我有一个简单的C#控制台项目,它正在处理S3 Bucket和s3对象。 It is very simple project and I can find an object and reading it with AmazonS3Client. 这是一个非常简单的项目,我可以找到一个对象并使用AmazonS3Client读取它。
I use this reference for working : 我使用此参考进行工作:
for example this function is apart of my project: 例如,此功能是我的项目的一部分:
public static string GetSpecialObject(string FileName, string BucketName)
{
AmazonS3Client client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest1);
// Create a GetObject request
GetObjectRequest request = new GetObjectRequest
{
BucketName = BucketName,
Key = FileName
};
using (GetObjectResponse response = client.GetObject(request))
{
using (StreamReader reader = new StreamReader(response.ResponseStream))
{
string contents = reader.ReadToEnd();
return contents;
}
}
}
As you see it is finding a file in bucket and I can return the value of file. 如您所见,它正在存储桶中找到文件,我可以返回文件的值。 What is the problem ? 问题是什么 ?
I created a AWS-Lambda Project (AWS-Lambda Function) and I am trying to use GetSpecialObject function there. 我创建了一个AWS-Lambda项目(AWS-Lambda函数),并且尝试在其中使用GetSpecialObject函数。 (.Net Core 2) (.Net Core 2)
I published my new project with AWS Toolkit on AWS but when I run it with Invoke button,I see this error : 我在AWS上使用AWS Toolkit发布了新项目,但是当我使用Invoke按钮运行它时,看到此错误:
"errorType": "MissingMethodException", "errorMessage": "Method not found: 'System.Collections.Generic.IList
1<System.String> Amazon.Runtime.SharedInterfaces.ICoreAmazonS3.GetAllObjectKeys(System.String, System.String, System.Collections.Generic.IDictionary
2)'.", "stackTrace": [ "at App.AWSFileClass..ctor(String accessKey, String secret, String bucket)", ......" ] } “ errorType”:“ MissingMethodException”,“ errorMessage”:“未找到方法:'System.Collections.Generic.IList1<System.String> Amazon.Runtime.SharedInterfaces.ICoreAmazonS3.GetAllObjectKeys(System.String, System.String, System.Collections.Generic.IDictionary
2)'。“,” stackTrace“:[”在App.AWSFileClass..ctor(String accessKey,String secret,String bucket)“,......”]}
It seems we can not use this class (AmazonS3Client) for AWS-Lambda service. 看来我们不能将此类(AmazonS3Client)用于AWS-Lambda服务。 I googled a lot about it. 我用谷歌搜索了很多。 I figure-out there are some libraries for Amazon S3 that we can add in Nuget and names are : 我发现有一些我们可以在Nuget中添加的Amazon S3库,名称为:
But these library are very weak. 但是这些库非常薄弱。
1 - Is there anyway to use AmazonS3Client class in AWS Lambda(.net core 2) ? 1-是否在AWS Lambda(.net core 2)中使用AmazonS3Client类吗?
OR 要么
2 - Is there anyway to give me a suggestion for working with S3Client class for reading an s3object ? 2-是否有给我建议使用S3Client类读取s3object?
AmazonS3Client is definitely supported in .NET Core 2.0. NET Core 2.0绝对支持AmazonS3Client。 It looks like you are using the .NET Framework version of the SDK instead of the .NET Core. 似乎您使用的是.NET Framework版本的SDK,而不是.NET Core。 I can tell because in your code you are calling the synchronous GetObject call which is only supported in .NET Framework. 我可以告诉您,因为在您的代码中您正在调用同步GetObject调用,而该方法仅在.NET Framework中受支持。 For .NET Core you should only see GetObjectAsync 对于.NET Core,您应该只看到GetObjectAsync
I'm curious how you got this to compile. 我很好奇您是如何编译的。 Was this code factored in a class library that is targeting .NET Framework and not .NET Standard? 该代码是否在针对.NET Framework而不是.NET Standard的类库中分解?
If you are directly adding dll you should be adding NuGet packages instead. 如果直接添加dll,则应添加NuGet软件包。 Add the AWSSDK.S3 NuGet package and make sure you don't have any dll references to AWSSDK.Core.dll and AWSSDK.S3.dll. 添加AWSSDK.S3 NuGet包,并确保您没有对AWSSDK.Core.dll和AWSSDK.S3.dll的任何dll引用。 By adding the NuGet package it will resolve to the correct platform version 通过添加NuGet软件包,它将解析为正确的平台版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.