Building a Serverless REST API in .NET with AWS Lambda

  Рет қаралды 75,585

Nick Chapsas

Nick Chapsas

Күн бұрын

Get $50 free AWS Credit by adding "AWS CREDIT #NICK" in the "Tell us about your project" area: bit.ly/nickaws
Get the source code: github.com/Elfocrash/aws-videos
Check out my courses: dometrain.com
Become a Patreon and get source code access: / nickchapsas
This video is sponsored by AWS
Hello everybody I'm Nick and in this video I will show you how you can build a completely serverless REST API in .NET using AWS Lambda. It is as simple as taking an existing REST API and adding A SINGLE LINE OF CODE! That being said, I do want to give some context so in this video we will also see how we got there.
Don't forget to comment, like and subscribe :)
Timestamps
Intro to AWS Lambda - 0:00
Creating a serverless API - 7:17
Turning our REST API serverless - 11:30
Social Media:
Follow me on GitHub: bit.ly/ChapsasGitHub
Follow me on Twitter: bit.ly/ChapsasTwitter
Connect on LinkedIn: bit.ly/ChapsasLinkedIn
Keep coding merch: keepcoding.shop
#aws #dotnet #serverless

Пікірлер: 136
@Dustyy01
@Dustyy01 2 жыл бұрын
Whats rly funny is that Nick does so much for Microsoft in general. Microsoft: 👀 Amazon: Lets give this man some money
@nickchapsas
@nickchapsas 2 жыл бұрын
Honestly AWS is the best sponsor I ever had. I've been using them for the past 3 years professionally and they've been constantly improving and investing in their .NET support and SDKs. Really glad they support .NET content creation.
@Dustyy01
@Dustyy01 2 жыл бұрын
@@nickchapsas For sure, I mean the simple abstractions they provide in addition to their libraries are so convenient and show that they really want devs to use their stuff
@antonmartyniuk
@antonmartyniuk 2 жыл бұрын
I am really impressed that with just a single line of code we can turn a webapi application into a serverless lambda. nice work from AWS team
2 жыл бұрын
I had to step back a bit to grab this concept: "Serverless is a cloud-native development model that allows developers to build and run applications without having to manage servers. There are still servers in serverless, but they are abstracted away from app development."
@nagarajansubramani
@nagarajansubramani 2 жыл бұрын
Exactly! For this reason, I wished Serverless were termed Serverblind instead. Oh well 🤷‍♂️
2 жыл бұрын
@@nagarajansubramani I'm in IT for 35 years and keep hearing new terms that make me look like an idiot. I wish we could try more in using amalgam of basic terms - Serverblind is quite intuitive so is server independent or server with normalized api module to connect to.
@parlor3115
@parlor3115 2 жыл бұрын
Are Lambdas (and their equivalents from other providers) the only way to do serverless through?
@Kazi2812
@Kazi2812 2 жыл бұрын
@@parlor3115 Azure Functions are the same. A much more intuitive name.
@MrOboema
@MrOboema 2 жыл бұрын
@@Kazi2812 Really? Azure Functions sounds like a chapter in a book that summerizes what Azure can be used for, meant for non-techies 😁
@petkopetkov4230
@petkopetkov4230 Жыл бұрын
You are an alien man. Writing and speaking without any hesitation, just phenomenal. Kudos!
@gravious
@gravious 2 жыл бұрын
i just got a job writing REST APIs with Lambda, this video is the perfect primer. You rock Nick! :D
@Code_Bits
@Code_Bits 2 жыл бұрын
I've build many API's like this but not using AWS Lambdas, but Azure Functions. It's indeed dirt cheap, you can even set up availablitiy checks for your API's and log everything while barely spending money.
@TopLel123
@TopLel123 2 жыл бұрын
Could you make a video or leave a comment about how you find new things to learn/what resource you use/what you follow and what's your proceess for learning new things? I'd be really interested because it always seems like you're on top of everything. Thank you!
@michaelkurzewski2937
@michaelkurzewski2937 2 жыл бұрын
AWS sponsorship! Big things! :) All the best on your new career path!
@BrunoJuliao7
@BrunoJuliao7 2 жыл бұрын
All the videos you suggested sounds cool. I would enjoy watching them 😇
@Marcel-dt5du
@Marcel-dt5du 2 жыл бұрын
Would really love to see a comparison between durable Azure Functions vs AWS step functions. I think the AWS part would nicely complement this video.
@Xblade-Dev
@Xblade-Dev Жыл бұрын
Thanks for doing this in Rider, the best IDE :)
@stanimirkolev584
@stanimirkolev584 2 жыл бұрын
We need more Azure tutorials
@TroyCSchmidt
@TroyCSchmidt 2 жыл бұрын
Yes to testing and infrastructure as code!!
@leesteve6842
@leesteve6842 Жыл бұрын
it is so great👍
@PereViader
@PereViader 2 жыл бұрын
You are a legend. "Let's go ahead and add 60 and 9"
@raghavgupta1157
@raghavgupta1157 2 жыл бұрын
Nice
@alvaromontoya3764
@alvaromontoya3764 2 жыл бұрын
Yes testing lambdas please
@Randomize-md3bt
@Randomize-md3bt 3 ай бұрын
THANK U,
@verdurakh
@verdurakh 2 жыл бұрын
So cool, is it possible to combine this with event bridge to deploy existing apis and run them as a scheduled job?
@kshitijurankar5254
@kshitijurankar5254 2 жыл бұрын
Hi Nick, Not related to posted video but can you make video on patteran and/or library to deal with processing huge files? How multi threading approach we should use?
@vaibhavmor1868
@vaibhavmor1868 2 жыл бұрын
Thanks! Do you plan on releasing a REST API course ? Love your previous three courses.
@nickchapsas
@nickchapsas 2 жыл бұрын
I do plan on release a course on REST yes. It will probably be the one after the Integration testing one that will launch late May/early June
@vaibhavmor1868
@vaibhavmor1868 2 жыл бұрын
@@nickchapsas thank you!
@jamescanady8156
@jamescanady8156 2 жыл бұрын
@nick I have a few questions. Is there a way to include ILambdaContext in the method parameters
@dpak2112
@dpak2112 2 жыл бұрын
Hi Nick, please make a video on cloud formation
@clearlyunwell
@clearlyunwell 2 жыл бұрын
This is great, Nick. So many random numbers, the calculation addition, and your date of birth LOL. More of these videos please.
@caunt.official
@caunt.official 2 жыл бұрын
Can you make tutorial on Orleans with AWS or Azure database?
@joshstather3543
@joshstather3543 2 жыл бұрын
10:24 . Nice
@wh33lers
@wh33lers 2 жыл бұрын
Could you also host a razor based page instead of an Api, or would this break the concept. Thanks for the content as always
@grupomexcomer
@grupomexcomer 10 ай бұрын
What about the cold start? Is that really a blocker from going to production for a big application? Or better choice go using NodeJS?
@JohnWatersKlas
@JohnWatersKlas Жыл бұрын
Is there a corresponding simple way to serve up an ApiController or MinApi project as a azure function? The one liner you had for lambda?
@antonmartyniuk
@antonmartyniuk 2 жыл бұрын
an AWS dedicated course will be a great thing indeed. any plans for it?
@alphaios7763
@alphaios7763 2 жыл бұрын
Hey, Nick. Could you please share your oh my posh theme? Maybe a repo that you could link in the description?
@lothar100
@lothar100 2 жыл бұрын
How do you write the JSON parameters in a cloud formation YAML? I must not be doing it right. I want to deploy with SAM in a stack, not just a standalone Lambda Function.
@JohnWatersKlas
@JohnWatersKlas Жыл бұрын
Hey Nick - this doesn't seem to work for dontnet 7 - which I am using for min API, and need features like Groups ... what to do?
@michaelakin766
@michaelakin766 Жыл бұрын
Hi Nick, any way you could connect this to ApiGateway and show how to inject the APIGatewayProxyRequest and get the stage variables?
@michaelakin766
@michaelakin766 Жыл бұрын
And also show Cognito Authorization and how to get the current logged in user in the minimal api.
@PaulSebastianM
@PaulSebastianM 2 жыл бұрын
What did you use to draw that square on top of the terminal (draw on screen)?
@Ultimatepritam
@Ultimatepritam 2 жыл бұрын
OhMyPosh theme
@m1dway
@m1dway 8 ай бұрын
how do you get the aws-lambda-tools-defaults.json created for an existing project? I don't have it with me
2 жыл бұрын
Always nice video! I know that lambda have a limit storage and limit time of process, so if our api have to process big data on long time, our api will broken for this lambda restrictions ?
@nickchapsas
@nickchapsas 2 жыл бұрын
You shouldn’t be using lambdas for things that take a long time to process. You pay by duration and memory so it is recommended that you use an actual service instead for things that need to process something for longer than a few seconds
@tarrencedavis7813
@tarrencedavis7813 2 жыл бұрын
Is there anyway to rate-limit function URL endpoints for a Lambda function? Related question: is there anyway to protect the function URL against DOS attacks?
@PelFox
@PelFox Жыл бұрын
Put them behind eg. Apim.
@vivekgowda1576
@vivekgowda1576 2 ай бұрын
Is this a good approach to use If we build large applications using a clean architect? or can we create a lambda function for each controller level to reduce the burden on lambda?
@Arapa007
@Arapa007 2 жыл бұрын
Great video as always! Any tip on how to reduce the cold start issue?
@nickchapsas
@nickchapsas 2 жыл бұрын
In reality, other than optimizing your startup, there isn't much you can do. Source generators do help with that and .NET is just naturally becoming faster as it goes so it will get better. That being said, if you expect the API to be busy, you don't really have to worry about it. I've seen people use "Warmers" which is basically just a periodic "ping" to the lambda to keep it warm but I don't know how I feel about that.
@EmptyGlass99
@EmptyGlass99 2 жыл бұрын
In AWS you can configure Lambdas to be always provisioned i.e. always ready and waiting to go - no cold starts. However, it costs more.
@PatrickMageez
@PatrickMageez 2 жыл бұрын
What's cheaper? Aws lambda for an api or a docker container in aws
@nickchapsas
@nickchapsas 2 жыл бұрын
@@PatrickMageez Depends on request duration and memory consumption but in general lambdas are cheaper
@Stealthy5am
@Stealthy5am 2 жыл бұрын
@@EmptyGlass99 you'll still get cold starts if you get n+1 concurrent requests where n is the number of instances you provision. So you don't solve the problem you just push it further away.
@HenriqueGraca
@HenriqueGraca Жыл бұрын
Hey Nick, great content as always. I think there is an error on you example (at least that is the only way that worked for me), When you configure the function-handler, it should be . (period) instead of : (colon) between SimpleApi and Functions, the working string "SimpleApi::SimpleApi.Functions::Get" EDIT: I see you fixed it during the video :)
@sunnypatel1045
@sunnypatel1045 2 жыл бұрын
Hi Nick why do you use FastEndpoint rather then your structured reflection? Have you done some benchmarking by any chance?
@nickchapsas
@nickchapsas 2 жыл бұрын
Overall I prefer FastEndpoints just because of the features you get out of the box. It's basically what my structured reflection would look like if I finished
@sunnypatel1045
@sunnypatel1045 2 жыл бұрын
@@nickchapsas I will need to look into it. I currently got an implementation of your reflection structure with mediatR. But will compare both 😬. Thanks dude and good to see you at NDC!
@garyc9402
@garyc9402 5 ай бұрын
What is the IDE that you're using in the video?
@DerekWelton
@DerekWelton 2 жыл бұрын
Off topic question Nick, what software are you using to markup your screen and zoom?
@nickchapsas
@nickchapsas 2 жыл бұрын
It’s called ZoomIt
@anre1318
@anre1318 2 жыл бұрын
Hey Nick! Whats about startup time if I have a huge startup function including DB Context etc.. Does this affect my response time? Probably or?
@nickchapsas
@nickchapsas 2 жыл бұрын
It will affect the first execution but not future ones, unless the lambda goes cold (uncalled for 30-45 minutes)
@anre1318
@anre1318 2 жыл бұрын
@@nickchapsas Hey Nick! Thanks for response. I am trying the third(?) approach, just adding services.AddAWSLambdaHosting(LambdaEventSource.RestApi); on Startup. Deploying via Terraform and then create Function URL is working fine and I can just call my endpoints. Do you know, what I need to do to integrate it with ApiGatway? Just proxying everything but I receive error: Object reference not set to an instance of an object. at Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayHttpApiV2ProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)
@Koolakoola-ve7sq
@Koolakoola-ve7sq 9 ай бұрын
why did you use functions url and not api gateway?
@aarzoomanoosi
@aarzoomanoosi Жыл бұрын
Please list down all AWS policies that we needed to allow the access to deploy this lambda function
@olegkot3362
@olegkot3362 2 жыл бұрын
Could you show something like this via Azure?
@nickchapsas
@nickchapsas 2 жыл бұрын
I haven't used Azure Functions in 3 years so I don't know for sure.
@butchakakakopf2601
@butchakakakopf2601 2 жыл бұрын
Yes, here is a wish too.
@Rubacava_
@Rubacava_ 2 жыл бұрын
It's really easy with vscode azure functions extension. It creates the boilerplate code for you. All you need is to paste your function and hit deploy.
@nickchapsas
@nickchapsas 2 жыл бұрын
@@Rubacava_ So you can take a full ASP.NET Core project and deploy it as an API in Azure Functions? Because that's what they are asking.
@jinalpatel9154
@jinalpatel9154 2 жыл бұрын
@@nickchapsas nice video and I have same question. This is really interesting that we can convert Web API it self into Lambda instead of having different hosting model that Azure function is using for in process and out of process.
@jadejahardisinh
@jadejahardisinh Жыл бұрын
@Nick Chapsas - How can we achieve same goal with API gateway? Because API Gateway provides custom domain facility.
@user-uq8dn4mt6o
@user-uq8dn4mt6o 6 ай бұрын
what editor is that?
@TheHydrogen4
@TheHydrogen4 2 жыл бұрын
What is that at 6:43? var rsp = new { query, message ="" }; When was that implemented? what is it called? is it a class, a struct? Is it type object? Never seen that json like syntax in cs before
@nickchapsas
@nickchapsas 2 жыл бұрын
It’s an anonymous object. It’s been there for many years
@TheHydrogen4
@TheHydrogen4 2 жыл бұрын
@@nickchapsas What version? I cant get the compiler to recognize the syntax. I am currently using .Net core 3.1
@anatoliypronyk1833
@anatoliypronyk1833 2 жыл бұрын
go IaC! it would be great
@pavl0britt207
@pavl0britt207 2 жыл бұрын
Could you help me please, I don't have New Project templates after installation of amazon tools
@pavl0britt207
@pavl0britt207 2 жыл бұрын
Fix! dotnet new --install Amazon.Lambda.Templates::6.1.1 help me
@user-iy5xb7us1l
@user-iy5xb7us1l 2 жыл бұрын
What if I create a bunch of functions for each endpoint instead of one lambda for all routes? This basically what serverless framework do but I wonder the difference in performance.
@BrendonParker
@BrendonParker 2 жыл бұрын
Actually, it performs better to have them all in one lambda. You don't pay the cold start cost for each lambda endpoint.
@LilPozzer
@LilPozzer 11 ай бұрын
Hi! I'm trying to upload a published x64 zip app to lambda, but it doesn't work and says me in the logs "Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format.", I tried every runtime, changed even in the lambda settings, NOTHING. im crying
@petrowi
@petrowi 2 жыл бұрын
My company has invested heavily in Azure, can you demonstrate a serverless app with Azure Functions?
@nickchapsas
@nickchapsas 2 жыл бұрын
I haven't used Azure Functions extensively so no
@waltavista
@waltavista 2 жыл бұрын
Apart from the fact that this video is great: For Azure Functions open Visual Studio, new Azure Function project, HTTP trigger...., right click "Publish"...
@christophem6373
@christophem6373 2 жыл бұрын
A video about Application Insight ?
@nickchapsas
@nickchapsas 2 жыл бұрын
I don't use Application Insights so no
@MrOboema
@MrOboema 2 жыл бұрын
Maybe its in the video, and I glanced over it, but...in case of the "regular" API, the downside is cold-start of the API itself, as discussed in the video. Does in here know why this is cold-start in necessary? I understand not every API app registered in AWS, can be loaded in memory at all times and ready to go in case a client needs it, but I dont see why this is in case of a "regular" REST API, and not in case of the API specifically written for AWS Lambda.
@czajla
@czajla Жыл бұрын
Why it always goes this way? dotnet new -i Amazon.Lambda.Templates return error: Can't install packet ... because packet does not exits. Am I missing any prerequisites?
@SupraStututututu
@SupraStututututu 13 күн бұрын
How did you connect to AWS? I see you just created a new project and it published AWS lambda directly to your AWS account without connection being specified
@mattiaricci910
@mattiaricci910 2 жыл бұрын
is it possible to deploy an entire dotnet solution usgin this method? i have an api with 5 projects (one of which is the controller based api), what configuration would i need to deploy the solution on aws lambda?
@nickchapsas
@nickchapsas 2 жыл бұрын
Sure you can, but I would recommend invidious deployment pipelines and separate lambdas per api
@mattiaricci910
@mattiaricci910 2 жыл бұрын
@@nickchapsas thank you nick! if i were to do it (for testing purposes) i would just need to add lambda hosting and set the function-handler as the name of the project that has the controller in it, is that right?
@mattiaricci910
@mattiaricci910 2 жыл бұрын
just an update, i managed to get i to work, i only needed to allow the lambda to access my rds instance, now it's working as intended
@sunilanthony17
@sunilanthony17 2 жыл бұрын
We use Azure only, can you create a video to create serverless REST API in Azure?
@stefanstojanovic7596
@stefanstojanovic7596 2 жыл бұрын
What kind of terminal is that with colors and git branch info?
@nickchapsas
@nickchapsas 2 жыл бұрын
It's Powershell Core through the WIndows Terminal with oh-my-posh installed
@stefanstojanovic7596
@stefanstojanovic7596 2 жыл бұрын
@@nickchapsas thank you!
@slicerdw1
@slicerdw1 2 жыл бұрын
How does API GW plays a role in these scenarios?
@nickchapsas
@nickchapsas 2 жыл бұрын
With Function URLs it doesn't need to
@michaelakin766
@michaelakin766 Жыл бұрын
Did I miss where you created the aws config?
@nickchapsas
@nickchapsas Жыл бұрын
My workstation is authenticated so I don't need to authenticate against the service in the same way that the app would be authenticated so there is no need for credentials
@michaelakin766
@michaelakin766 Жыл бұрын
@@nickchapsas I was talking about the aws-lambda-tools-defaults.json file.
@michaelakin766
@michaelakin766 Жыл бұрын
Oh, I just saw where you said you added it. How did you find the structure of the file to add?
@osman3404
@osman3404 2 жыл бұрын
Is the same thing possible for azure functions? If not it’s very ironic since both azure serverless functions and minimal api are both from Microsoft lol
@nickchapsas
@nickchapsas 2 жыл бұрын
The "turning an asp.net core api to an azure function with just one line of code" part, isn't AFAIK
@narebinhaa
@narebinhaa 9 ай бұрын
After running "dotnet lambda deploy-function on Windows 11, I am running into this error. Does anyone knows how to sove it? "publish: C:\Program Files (x86)\dotnet\sdk\7.0.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(470,5): error : Error: Unable to load DLL 'clrjit_unix_x64_x86' or one of its dependencies: The specified module could not be found. (0x8007007E)"
@adelarsq
@adelarsq Жыл бұрын
Legal
@PaulSebastianM
@PaulSebastianM 2 жыл бұрын
69... Nick! This is a programmer friendly community! 😂😂😂😂
@marcotroster8247
@marcotroster8247 2 жыл бұрын
Hey guys, can you explain to me why I would want serverless? (serious question, I'm open to argue) What enthusiasts are telling me is "it's cheap and you don't need an ops team anymore". But I strongly doubt that. "Infinite scaling" seems to be a reasonable goal, but it comes at the cost of decomposing the system to an extent where noone can even understand what's going on. So, is it really as desirable as people are telling me all the time? 😅
@nickchapsas
@nickchapsas 2 жыл бұрын
It is. When it makes sense for a usecase it is a no brainier. It’s cheaper, you have less things to manage, deployment is easier, scaling is easier, monitoring is easier and you get tons of native integrations with other services within your cloud provider of choice. You can focus on building a product over everything around it
@marcotroster8247
@marcotroster8247 2 жыл бұрын
@@nickchapsas Thank you. Sounds reasonable for smaller projects or startups 😄 You know, I've heard of companies who are running 10-100k of lambda endpoints in their deployment and literally lost control over which lambda they actually need and which they can turn off. Isn't this a big concern when the codebase is growing out of control? 🤔
@nickchapsas
@nickchapsas 2 жыл бұрын
@@marcotroster8247 Actually it's great for big companies as well. We use them extensively to build our products and we prefer them over traditional microservice. We use Backstage to keep track of everything and we have really good APM. Don't dismiss them. In most cases they are a better and more manageable approach than microservices
@clearlyunwell
@clearlyunwell 2 жыл бұрын
👍🏽
@clashclan4739
@clashclan4739 2 жыл бұрын
you should have used Azure 😥😥
@jeffreychong7928
@jeffreychong7928 2 жыл бұрын
Oh man, I am not the first one leVe comment
@StarsTogether
@StarsTogether 8 ай бұрын
Good stuff! Want more on this? I recommend a book that aligns with this content. "AWS Unleashed: Mastering Amazon Web Services for Software Engineers" by Harrison Quill
@DaminGamerMC
@DaminGamerMC 2 жыл бұрын
I have been programming for many many years in many different languages but I really do not understand any of this. I do know what a Rest API but that is it... I know this Cloud Programming stuff is becoming a very important thing but I dont even know where to start to learn and undertsand all of this.
@sunnypatel1045
@sunnypatel1045 2 жыл бұрын
The only way to learn is by doing mate. Read documents and go through step by step tutorials AWS and Azure done a fantastic job on docs.
@user-yn3ee9uj3l
@user-yn3ee9uj3l 2 жыл бұрын
IMO aws lambda is way better and intuitive than azure functions for c# development. What a shame!
@bigbull3112
@bigbull3112 Жыл бұрын
How did you publish to Lambda without using any key, connection to AWS? not clear. too fast. not for teaching but just for show off
@Bleppacus
@Bleppacus 2 жыл бұрын
"Building a Serverless..". "What i just want to do is to deploy that straight away". Serverless does not exist. It is still hosted somewhere..
@nickchapsas
@nickchapsas 2 жыл бұрын
Serverless doesn’t mean there is no server. It means that to you building and deploying the API, there is no server.
@alexliroyd3684
@alexliroyd3684 2 жыл бұрын
69 - nice
@Ristogod
@Ristogod 2 жыл бұрын
I don't see AWS as viable given that they've demonstrated their willingness to just disable your stuff if you don't agree with "the message"
@quranthecompanion4528
@quranthecompanion4528 2 жыл бұрын
you are using more AWS lately. SOFT promotion, lol
@nickchapsas
@nickchapsas 2 жыл бұрын
I’ve been exclusively using AWS for the past 3 years. I don’t use Azure
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 309 М.
Create Your First AWS Lambda Function | AWS Tutorial for Beginners
12:44
Tiny Technical Tutorials
Рет қаралды 129 М.
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 4,7 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 11 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 8 МЛН
"I Lost a Job Because of This Codebase"
14:08
Nick Chapsas
Рет қаралды 60 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 249 М.
The Easiest Way to Create Serverless APIs in .NET
18:14
Nick Chapsas
Рет қаралды 40 М.
The New .NET 9 HybridCache That You Must Upgrade To!
14:34
Nick Chapsas
Рет қаралды 47 М.
Writing C# without allocating ANY memory
19:36
Nick Chapsas
Рет қаралды 145 М.
МАМА И STANDOFF 2 😳 !FAKE GUN! #shorts
00:34
INNA SERG
Рет қаралды 4,7 МЛН