WinSCP.exe 在 .NET Core AWS Lambda 函数中丢失。

huangapple go评论68阅读模式
英文:

WinSCP.exe missing in .NET Core AWS Lambda Function

问题

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 an AWS Lambda function I get the following error on Session.Open():
> WinSCP.SessionLocalException: The winscp.exe executable was not found at the 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 the path to winscp.exe.

I am aware that for an 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

英文:

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

答案1

得分: 0

我不知道Amazon Lambda是否提供存储空间,用于存储winscp.exe,就像Azure Functions一样。

但这可能并不重要,因为WinSCP是Windows二进制文件,而Amazon Lambda(与Azure Functions相反)仅提供Linux系统:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

所以恐怕您不能在Amazon Lambda中使用WinSCP。

英文:

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.

答案2

得分: 0

感谢Martin的回答,这将使我免于在Lambda中努力让WinSCP工作时撞墙。我还找到了与您的答案相关的备份:

Lambda执行环境基于特定的Amazon Linux AMI和内核版本。在Lambda部署包中使用的任何本机二进制文件必须在此环境中编译,仅支持64位二进制文件。

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

我可能会尝试使用NuGet包SSH.NET,因为它似乎是一个.NET 6库,因此(我希望是的 :-))受Amazon Linux支持。

Henrik

英文:

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

huangapple
  • 本文由 发表于 2023年6月15日 20:45:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482620.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定