Тёмный
No video :(

The Simplest Way To Build .NET 8 Native AOT Lambda Functions 

James Eastham
Подписаться 3,9 тыс.
Просмотров 5 тыс.
50% 1

Опубликовано:

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@BenSycha
@BenSycha 9 месяцев назад
Cheers for the video. This is going to help shape my days planned training to get up to date with C# and lambdas after being a few years away from dotnet development
@serverlessjames
@serverlessjames 9 месяцев назад
I've got a playlist on my channel on AWS SAM & .NET. I'd recommend that as a place to start as its a bit more step by step. I'm actually considering doing a 'zero to hero' playlist so let me know what areas specifically would be interesting to you.
@MichaelThwaite
@MichaelThwaite 9 месяцев назад
I'm ½ there! Keeping everything else the same, Rider macOS ARM, .net8, what would a Minimal API look like compiled AOT and deployed to Lambda. FYI: I'm using the 'dotnet lambda deploy-function ...' and connect a Load Balancer to my Lambda's at the moment, something that works very well for me.
@serverlessjames
@serverlessjames 9 месяцев назад
I've got a video in the works for this, im just pulling something together that uses a more 'typical' .NET stack. That'll probably be out the week after reInvent. There's an example on our benchmarking repo though that should help you get started. github.com/aws-samples/serverless-dotnet-demo/tree/main/src/NET8NativeMinimalAPI
@seankirk2397
@seankirk2397 9 месяцев назад
Awesome video as always, James ! Thank you for sharing! Random question for the Amazon.Lambda.Annotations package -- there is no requirement that one must use AWS SAM for deployment when utilizing this package, right? Since the package is leveraging source generators, it’s all compile time-magic to generate the boiler plate code and there no SAM-specific dependency for actually deploying to AWS? For instance, we use the Serverless Framework for our .NET application deployments to AWS; if I'm thinking about this correctly, I think we could leverage this package in our current approach and would just need to ensure that we include and correctly value the ANNOTATIONS_HANDLER environmental variable when we register our Lambdas in the project. Will give this a try but just wanted to see if there was anything obvious that I’m missing. Thanks again for the quality content!
@serverlessjames
@serverlessjames 9 месяцев назад
Yeah that's correct, you could use it with whatever tooling you use to deploy. I use annotations with CDK pretty regularly. As you say, just make sure you set the environment variable and your output assembly to be called bootstrap (if you're using custom runtimes)
@sabarishsathasivan
@sabarishsathasivan 8 месяцев назад
@@serverlessjames We use Service Catalog and CF , will this work with that
@serverlessjames
@serverlessjames 8 месяцев назад
I see no reason why not, you might have to just make sure you first manually compile the application code inside AL2 and then just reference the compiled zip
@OhWhyMeGod
@OhWhyMeGod 17 дней назад
Thanks for the great video @serverlessjames I figure I must be doing something wrong. I can run dotnet build fine but when I attempt to run sam build --use-container --mount-with WRITE --build-image plantpowerjames/dotnet-8-lambda-build:8.0.100-arm64 it errors with: Error: DotnetCliPackageBuilder:Validation - Runtime dotnet8 is not supported Workflow DotnetCliPackageBuilder does not support value "False" for building in source. Using default value "True". my SAM version is SAM CLI, version 1.121.0 Any idea on the issue? Thanks!
@user-jr1yw4jm9c
@user-jr1yw4jm9c 9 месяцев назад
Thanks for the video. Can you please share where you define the "Partial" class public partial class CustomJsonSerializerContext : JsonSerializerContext what annotations does it require? Just these two? [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))] [JsonSerializable(typeof(APIGatewayHttpApiV2ProxyResponse))]
@serverlessjames
@serverlessjames 9 месяцев назад
It requires annotations for whatever objects you need to be available for serialisation. If you only need to work with the 2 API Gateway objects then yes, the 2 attributes you have mentioned are the only two you will need.
@sumarianprince
@sumarianprince 8 месяцев назад
Hey James, love your videos. I was able to get the native AOT working on 7.0 quite easily, with your 8.0 image it doesn't work on AWS. Am I doing something wrong? I am trying to use a single purpose function that does something with the querystring input.
@serverlessjames
@serverlessjames 8 месяцев назад
First off, thankyou. When you say it doesn't work, could you provide more specifics?
@sumarianprince
@sumarianprince 8 месяцев назад
@@serverlessjames I am using Amazon 2 ARM64 as my Lambda type, I am just trying to get your NET8Native.sln hosted on a Lambda. I am specifically interested in this because I need to get my code working on DOTNET 8.0 on the Graviton processor. I don't see where you are using your own custom image thanks!
@serverlessjames
@serverlessjames 8 месяцев назад
Is the machine you are running the build on and ARM based machine? What specific error are you seeing?
@sumarianprince
@sumarianprince 8 месяцев назад
@@serverlessjames It's a Windows 11 machine. I am using a docker image to compile it for Arm64 since I don't have an Arm64 processor machine.
@devch4716
@devch4716 8 месяцев назад
@sumarianprince I couldn't get it to work either on my Windows 10 machine. I wished @serverlessjames could give more detail into the cloudformation settings for Metadata. Fo instance, I use the serverless.templates with parameter files instead of the SAM template.yaml...so I'm trying to convert all of this over. But still trying to follow the instructions are not working for me, even after downloading the complete source.
@user-ut3do7se5f
@user-ut3do7se5f 6 месяцев назад
Hi James, thanks for the video. Is it possible to override the response and set a custom ApiGatewayHttpApiV2ProxyResponse?, for example if we need to return a base64 encoded response
@serverlessjames
@serverlessjames 6 месяцев назад
As in, include Base64 as part of the body? Or ONLY return a Base64 string?
@user-ut3do7se5f
@user-ut3do7se5f 6 месяцев назад
@@serverlessjames return a Base64 string and mark the IsBase64Encoded flag true
@user-ut3do7se5f
@user-ut3do7se5f 6 месяцев назад
Hey James, I hope my question is clear, if not I can further clarify. Also another question, is it possible to access the request headers while using the [LambdaFunction] annotation?
@purplebytessolutions6994
@purplebytessolutions6994 6 месяцев назад
Hi James, i am using the Amazon.Lambda.Annotations nuget in my project with an outputType of Exe and AssemblyName of Bootstrap. However, i keep getting this error when compiling: Error CS5001 : Program does not contain a static 'Main' method suitable for an entry point. And this [assembly: LambdaGlobalProperties(GenerateMain = true, Runtime = "provided.al2")] should fix that however the compiler can't resolve the symbol LambdaGlobalProperties even though i have the nuget for Annotations and Lambda.Core ?? any ideas..
@serverlessjames
@serverlessjames 6 месяцев назад
What version of Lambda annotations are you using? You'll need to be using the latest for the LambdaGlobalProperties attribute to be available
@purplebytessolutions6994
@purplebytessolutions6994 6 месяцев назад
Up'ed the version as you suggested.. issue fixed! big thanks@@serverlessjames
@TheParfster
@TheParfster 7 месяцев назад
Does this method mean that each "lambda" has all the code and dependencies of all the other lambda functions from the csproject? Or is it smart enough to only include everything from the relevant function. I only say that as if it is just the whole api in each lambda but with that switch statement in the generated main function choosing which to use, how is that any better than just having an entire .net 8 api in a single lambda?
@serverlessjames
@serverlessjames 7 месяцев назад
Correct, all Lambda functions would include all the code. With the optimizations of native AOT this isn't a huge problem. Your point about a whole API is a valid one. ASP.NET isn't fully supported with AOT for one thing, so that could be a reason. I do think the entire API in a Lambda is a good pattern. For something small and simple, you avoid the overhead of ASP.NET and you will get better performance. My long rambling answer has told me I need to produce a video on this topic, so keep your eyes peeled 👌
@TheParfster
@TheParfster 7 месяцев назад
@@serverlessjames I look forward to it. I have come round on this idea though as I guess it will be faster and more lightweight simply just by not having all the surrounding web api code as this is all handled by the apigateway routing into the lambda. I have been trying to set this native aot lambda annotations stuff up in a new project, do you know if there is a way to still use the generated serverless.template? I believe in this video you are using the non auto generated sam template that comes in that github repo. Any help would be massivly appreciated.
@TheParfster
@TheParfster 7 месяцев назад
@@serverlessjames Tried copying the tutorial almost exactly just to get something working and keep seeing a permissions issue from what looks like inside the container Error: CustomMakeBuilder:CopySource - [Errno 13] Permission denied: '/tmp/samcli/source/.vs/NET8Native/FileContentIndex/2130ff9e-0503-4cb6-b355-b364867cfef5.vsidx' GetProductsFunction: Running CustomMakeBuilder:CopySource
@serverlessjames
@serverlessjames 7 месяцев назад
@TheParfster if you have a code sample on GitHub somewhere I'm happy to take a look...?
@vishnupg
@vishnupg 7 месяцев назад
My app is starting up.But gives error System.NotSupportedException: Reflection_InsufficientMetadata_EdbNeeded .Any suggestions
@serverlessjames
@serverlessjames 7 месяцев назад
Is this using the exact code from the video? Or your own code with native AOT enabled?
@vishnupg
@vishnupg 7 месяцев назад
@@serverlessjames no my own code and the error is coming from masstransit library
@vishnupg
@vishnupg 7 месяцев назад
No its from an application we developed.I was migrating it to dotnet 8.The error is coming from masstransit dll @@serverlessjames
@nofmxc
@nofmxc 9 месяцев назад
Do you use provided al2 in the SAM temple with dotnet7 build method? Or is it working some other way?
@serverlessjames
@serverlessjames 9 месяцев назад
Provided al2 with a makefile as the build method. Then when I run sam build I specify the --use-container flag to use my custom al2 .NET 8 build image
@YTN3rd
@YTN3rd 9 месяцев назад
@@serverlessjames Any plans to use provided.al2023 rather than al2?
@serverlessjames
@serverlessjames 9 месяцев назад
@YTN3rd yes, absolutely. I just need to create a build image that has .NET 8 installed. I'll try and get that together over the weekend 👌
@devch4716
@devch4716 8 месяцев назад
awesome! that image in your repo is 864.93 MB....yikes
@serverlessjames
@serverlessjames 8 месяцев назад
Yeah, it's a big one. It does package up the .NET SDK plus the AL2 OS. You can use a layered build in Docker though so you don't actually need to deploy the full 800mb. Also, a preview of the official image is available now so I'd recommend using that instead.
@devch4716
@devch4716 8 месяцев назад
@@serverlessjames can you share the link for the preview?
@serverlessjames
@serverlessjames 8 месяцев назад
@@devch4716 public.ecr.aws/lambda/dotnet:8-preview
@devch4716
@devch4716 8 месяцев назад
@@serverlessjames for AOT? Use this instead of the one in your example? I get this error "error : Cross-OS native compilation is not supported." FYI - I'm using the .Net 7 Container template and updated it to use net8.0 with the 8.0-preview image, and PublishAot=true
@serverlessjames
@serverlessjames 8 месяцев назад
@devch4716 could you drop me a message on social media? Either Twitter or LinkedIn. Will be easier to work out what you're trying to do than RU-vid comments 👌
@sanketpatil473
@sanketpatil473 8 месяцев назад
I have used base image like yours "public.ecr.aws/lambda/provided:al2-arm64" for dot net 8. I have added bootstrap file also but its not able to find "/var/task/LambdaEntryPoint::FunctionHandlerAsync.sh: No such file or directory" It works with dotnet 7 when I use this base image "public.ecr.aws/lambda/dotnet:7" I need to change something or add something more? public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction { protected override void Init(IWebHostBuilder builder) { builder .UseStartup(); } protected override void Init(IHostBuilder builder) { } }
@serverlessjames
@serverlessjames 8 месяцев назад
Interesting, it looks like you're using ASP.NET here right? Not single purpose functions? If you are trying to run ASP.NET on Lambda in this way you'll need to be using minimal APIs, and configure the ASPNET Lambda tooling that way.
Далее
Don't Use Polly in .NET Directly. Use this instead!
14:58
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Avaz Oxun - 10 yillik yubiley konsert dasturi 2023
2:52:33
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 267 тыс.
Don't throw exceptions in C#. Do this instead
18:13
Просмотров 257 тыс.
NVIDIA Needs to STOP - RTX 3050 & Misleading Branding
11:35
The Logging Everyone Should Be Using in .NET
15:34
Просмотров 61 тыс.
Is Blazor Better than React?
14:25
Просмотров 47 тыс.
We NEED To Talk About The War Within
24:51
Просмотров 233 тыс.
Fix Your Controllers By Refactoring To Minimal APIs
14:56
.NET 8 | What is Native AOT in .NET?
13:33
Просмотров 10 тыс.
What’s the Result Type Everyone Is Using in .NET?
14:47