简体   繁体   English

AmazonS3Client在AWS Lambda S3项目中不起作用

[英]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 : 我使用此参考进行工作:

  • AWSSDK.Core AWSSDK.Core
  • AWSSDK.S3 AWSSDK.S3


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.IList 1<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库,名称为:

  • Amazon.S3 Amazon.S3
  • AWSSDK.Core AWSSDK.Core

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.

相关问题 AmazonS3Client在带有FTP客户端的Lambda中不起作用 - AmazonS3Client does not work in Lambda with FTP Client 处理AmazonS3Client和S3Response - Disposing the AmazonS3Client and S3Response 使用 AmazonS3Client 将大型多部分上传流式传输到 S3 - Streaming large multi-part uploads to S3 using AmazonS3Client AmazonS3Client 挂在 PutObject - AmazonS3Client hanging at PutObject 使用 Autofac 上的配置注册更多 AmazonS3Client - Registering more AmazonS3Client with configurations on Autofac 如何使用 AmazonS3EncryptionClientV2 客户端加密从 AWS S3 存储桶下载 object? - How do you download object from AWS S3 bucket using AmazonS3EncryptionClientV2 client side encryption? 使用访问密钥,秘密密钥和RegionEndPoint构造函数在C#中实例化AmazonS3Client突然失败,出现DirectoryNotFoundException - Instantiating AmazonS3Client in C# using the access key, secret key and RegionEndPoint constructor is suddenly failing with DirectoryNotFoundException 在NETWORK_SERVICE(服务结构)下运行时,.Net Core中的AmazonS3Client构造函数将引发 - AmazonS3Client constructor in .Net Core throws when running under NETWORK_SERVICE (service fabric) 从 .net 核心中的 singleton 返回 AmazonS3Client 实例时如何确保线程安全使用 - How to ensure thread safe usage when returning an AmazonS3Client instance from a singleton in .net core AmazonS3Client 单连接与每次调用的新连接 C# - AmazonS3Client Single connection Vs new connection for each call C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM