1

I have followed this guide to deploy a .NET Core 3.0 application to AWS Lambda:

https://aws.amazon.com/blogs/developer/net-core-3-0-on-lambda-with-aws-lambdas-custom-runtime/

My serverless.template and aws-lambda-tools-defaults.json files are carbon copies from this article.

My app is an ASP.NET Core app with a target framework of netcoreapp3.0 using the Amazon.Lambda.AspNetCoreServer and Amazon.Lambda.RuntimeSupport packages.

When I run dotnet lambda deploy-serverless I get the error:

NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. Please either specify a RuntimeIdentifier or set SelfContained to false.

Every example I have seen shows this for the msbuild-parameters:

"msbuild-parameters": "--self-contained true /p:AssemblyName=bootstrap"

But obviously, I can try the dotnet publish --self-contained true command from the command line and I get the same error (NETSDK1031). How is this supposed to work?

If I change the command and run dotnet publish --self-contained true -f netcoreapp3.0 -r linux-x64 it publishes successfully on my local.

If I update the msbulid-parameters with the same required parameters and run dotnet lambda deploy-serverless I get:

... publish: MSBUILD : error MSB1009: Project file does not exist.

What am I missing?

2 Answers 2

4

After digging through the source code of the Amazon Lambda Dotnet CLI tools here: https://github.com/aws/aws-extensions-for-dotnet-cli/blob/6b3c0eaf04bb62995ca1c5dd71b0db7e564e8b74/src/Amazon.Lambda.Tools/LambdaDotNetCLIWrapper.cs)

I found the following code that builds the dotnet publish command:

// If you set the runtime to RUNTIME_HIERARCHY_STARTING_POINT it will trim out the Windows and Mac OS specific dependencies but Razor view precompilation
// will not run. So only do this packaging optimization if there are no Razor views.
if (Directory.GetFiles(fullProjectLocation, "*.cshtml", SearchOption.AllDirectories).Length == 0)
{
    arguments.Append($" -r {LambdaConstants.RUNTIME_HIERARCHY_STARTING_POINT}");

    if (msbuildParameters == null ||
        msbuildParameters.IndexOf("--self-contained", StringComparison.InvariantCultureIgnoreCase) == -1)
    {
        arguments.Append(" --self-contained false ");
    }

    if (string.IsNullOrEmpty(msbuildParameters) ||
        !msbuildParameters.Contains("PreserveCompilationContext"))
    {
        _logger?.WriteLine("... Disabling compilation context to reduce package size. If compilation context is needed pass in the \"/p:PreserveCompilationContext=false\" switch.");
        arguments.Append(" /p:PreserveCompilationContext=false");
    }
}

My site did indeed include a CSHTML since it was a full-stack web app. Adding the following parameter to the msbuild parameters fixes the issue: -r rhel.7.2-x64

But AWS Lambda is not meant to handle full stack applications and static files won't serve properly, so best bet is to break up the application so that the Asp.Net Core lambda project is just a pure API.

Sign up to request clarification or add additional context in comments.

1 Comment

(Author of this tool here) I'm planning on removing this check on *.cshtml as that is a leftover artifact from the .NET Core 1.0 days when razor pages were compiled at runtime. Now a days with .NET Core razor pages are precompiled when the project is built.
0

I had same issue and i moved /p:AssemblyName=bootstrap to my .csproj file. See attached image. enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.