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
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.
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.
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
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!
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)
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
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!
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))]
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.
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 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!
@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.
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
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?
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..
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?
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 👌
@@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.
@@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
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.
@@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
@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 👌
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) { } }
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.