1
votes

I have a simple C# console project that it is working with S3 Bucket and s3 objects. It is very simple project and I can find an object and reading it with AmazonS3Client.
I use this reference for working :

  • AWSSDK.Core
  • 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. (.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 :

"errorType": "MissingMethodException", "errorMessage": "Method not found: 'System.Collections.Generic.IList1<System.String> Amazon.Runtime.SharedInterfaces.ICoreAmazonS3.GetAllObjectKeys(System.String, System.String, System.Collections.Generic.IDictionary2)'.", "stackTrace": [ "at App.AWSFileClass..ctor(String accessKey, String secret, String bucket)", ......" ] }

It seems we can not use this class (AmazonS3Client) for AWS-Lambda service. 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 :

  • Amazon.S3
  • AWSSDK.Core

But these library are very weak.

1 - Is there anyway to use AmazonS3Client class in AWS Lambda(.net core 2) ?
OR
2 - Is there anyway to give me a suggestion for working with S3Client class for reading an s3object ?

1
How are you calling this method? If this is Lambda function, then it's not defined well (Lambda function has to have entry point).Caldazar
It is a part of my project. I cam calling this from Lambda Function main method.Mostafa Fallah

1 Answers

3
votes

AmazonS3Client is definitely supported in .NET Core 2.0. It looks like you are using the .NET Framework version of the SDK instead of the .NET Core. I can tell because in your code you are calling the synchronous GetObject call which is only supported in .NET Framework. For .NET Core you should only see 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?

If you are directly adding dll you should be adding NuGet packages instead. Add the AWSSDK.S3 NuGet package and make sure you don't have any dll references to AWSSDK.Core.dll and AWSSDK.S3.dll. By adding the NuGet package it will resolve to the correct platform version