aws / aws-extensions-for-dotnet-cli

Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
Apache License 2.0
369 stars 86 forks source link

Enable AOT publishing for AL2023 #294

Closed normj closed 7 months ago

normj commented 7 months ago

Description of changes: The deploy tooling when building for AOT will default to container builds unless we detect we on Amazon Linux. In that case container build defaults to false and we compile on the Amazon Linux instance. Originally the code only checked for AL2 but now that we have AL2023 and .NET 8 managed runtime will be based on this I extended the check for AL 2023.

I also added the .NET 8 target framework to the project file.

I verified the fix by spinning up an EC2 AL2023 instance and deployed an AOT function from there which did not trigger a container build.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

jamiewinder commented 5 months ago

I'm unsure what I'm missing to get this to work. I have ADO pipeline that builds my .NET 6 Lambda and I want to convert this to use .NET 8 with AOT. I've updated the project accordingly and made sure I'm on version 5.9 of these tools.

However, when dotnet lambda publish runs, I get the error:

Found /etc/os-release Architecture not provided, defaulting to x86_64 for container build image. No container build image available for targetFramework net8.0 and architecture x86_64.

So it appears to be defaulting to a container build which I suppose is what I'm trying to avoid. However the pipeline itself is running on Ubuntu 22. Do I just need to wait for a suitable container build image to be available or is there some configuration I'm missing to enable this now?

normj commented 5 months ago

@jamiewinder When building on a non Amazon Linux environment you need to use container build matching Lambda's runtime for AOT. Unfortunately we haven't released a .NET 8 Lambda build image yet. It should be released together with the managed runtime.

This PR was largely done to get the CLI tool ready for when the build image will released. So once it is released the tooling will just work.

Beau-Gosse-dev commented 5 months ago

@jamiewinder, in the meantime, you can build your own image to use, or for testing purposes (not production ready) you can use the image that James Eastham built like this: dotnet lambda deploy-function -cifb plantpowerjames/dotnet-8-lambda-build:al2023-8.0.100

(cifb stands for Container Image For Build)

James talks about it more here: https://youtu.be/kyb16r-Oul0?si=Fo9l7sS4xTii0ZEz