WinSCP.exe missing in .NET Core AWS Lambda Function

195 views Asked by At

I have developed a .NET Core 6.0 using WinSCP 6.1.0 NuGet package. Locally, from my own PC, I can access a SFTP server, obtaining connection and being able to PUT files.

When I deploy my app as a AWS Lambda function I get the following error on Session.Open():

WinSCP.SessionLocalException: The winscp.exe executable was not found at location of the assembly WinSCPnet (/var/task), nor the entry assembly Amazon.Lambda.RuntimeSupport (/var/runtime), nor in an installation path. You may use Session.ExecutablePath property to explicitly set path to winscp.exe.

I am aware that for a Azure Function I can set ExecutablePath like this, and it works:

[FunctionName(FunctionName)]
public static void Run([TimerTrigger("%XXXSendSchedule%")] TimerInfo myTimer, ILogger log, ExecutionContext executionContext)
     using (Session winscpSession = new Session())
     {
          // See https://winscp.net/eng/docs/guide_microsoft_azure_function_sftp
          winscpSession.ExecutablePath = Path.Combine(executionContext.FunctionAppDirectory, "winscp.exe");

However, in a Lambda function the ILambdaContext does not seem to have anything like Azure's FunctionAppDirectory:

public void MyFunctionHandler(ILambdaContext context)

Where can I find the path where the Lambda function keeps WinSCP.exe so that I can set Session.ExecutablePath?

Henrik

2

There are 2 answers

0
Martin Prikryl On BEST ANSWER

I do not know if Amazon Lambda offers storage where you could store the winscp.exe, the way Azure Functions do.

But it probably does not matter, as WinSCP is Windows binary and Amazon Lambda (contrary to Azure Functions) offers only Linux systems:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

So I'm afraid that you cannot use WinSCP in Amazon Lambda.

1
henrik55 On

Thanks Martin for your answer, it will save me from banging my head against the wall trying to get WinSCP to work in Lambda. I found also backup for your answer:

The Lambda execution environment is based on a specific Amazon Linux AMI and kernel version. Any native binaries that are used in a Lambda deployment package must be compiled in this environment, and only 64-bit binaries are supported.

From https://itnext.io/running-arbitrary-executables-in-aws-lambda-encrypting-a-pdf-afea47e3c345

I will probably try the NuGet package SSH.NET next, as it seems to be a .NET 6 library, hence (I hope :-)) supported by the Amazon Linux.

Henrik