aws / aws-toolkit-visual-studio

AWS Toolkit for Visual Studio - a plugin to interact with AWS
https://aws.amazon.com/visualstudio/
Apache License 2.0
107 stars 29 forks source link

Can I build a ReadyToTun instance targeting dotnet3.1 on Windows #168

Open pgrinsell opened 3 years ago

pgrinsell commented 3 years ago

I am deploying my dotnet application on lambda but I am having issues with cold starts. I've determined this is partly caused by JIT compilation time.

Lambda has recently introduced the dotnet3.1 runtime which supports ReadyToRun. This compiles the application ahead of time. https://aws.amazon.com/blogs/compute/announcing-aws-lambda-supports-for-net-core-3-1/

I have added the relevant msbuild parameters to my aws-lambda-tools-defaults.json file as follows:

"msbuild-parameters": "/p:PublishReadyToRun=true --self-contained false"

On build I get the following error:

error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false.

I have determined this is caused by me attempting to build a Linux instance on Windows as described in the ReadyToRun documentation: https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run#cross-platformarchitecture-restrictions

What is the simplest solution to this problem?

AWS SAM CLI supports a use-container flag which resolves similar issues by performing the build on the target operating system within a Docker container. Is there similar functionality available in AWS Toolkit?

awschristou commented 3 years ago

This limitation appears to also be present when using the Lambda deploy tool directly from the command line. Perhaps @normj has some insights?

One thing that you could try is to use container based Lambda images. This would allow you to build the linux based image from Windows, and deploy it to Lambda - https://docs.aws.amazon.com/lambda/latest/dg/csharp-image.html