Тёмный

Building a Serverless REST API in .NET with AWS Lambda 

Nick Chapsas
Подписаться 294 тыс.
Просмотров 76 тыс.
50% 1

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

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

 

7 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 😁
@gravious
@gravious 2 года назад
i just got a job writing REST APIs with Lambda, this video is the perfect primer. You rock Nick! :D
@petkopetkov4230
@petkopetkov4230 Год назад
You are an alien man. Writing and speaking without any hesitation, just phenomenal. Kudos!
@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!!
@PereViader
@PereViader 2 года назад
You are a legend. "Let's go ahead and add 60 and 9"
@raghavgupta1157
@raghavgupta1157 2 года назад
Nice
@leesteve6842
@leesteve6842 Год назад
it is so great👍
@alvaromontoya3764
@alvaromontoya3764 2 года назад
Yes testing lambdas please
@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?
@Randomize-md3bt
@Randomize-md3bt 3 месяца назад
THANK U,
@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?
@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
@joshstather3543
@joshstather3543 2 года назад
10:24 . Nice
@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?
@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.
@alphaios7763
@alphaios7763 2 года назад
Hey, Nick. Could you please share your oh my posh theme? Maybe a repo that you could link in the description?
@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
@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?
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.
@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?
@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?
@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.
@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
@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 12 дней назад
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
@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.
@christophem6373
@christophem6373 2 года назад
A video about Application Insight ?
@nickchapsas
@nickchapsas 2 года назад
I don't use Application Insights so no
@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"...
@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
Далее
The Easiest Way to Create Serverless APIs in .NET
18:14
İranda azərbaycanlı prezident seçilib
00:32
Просмотров 298 тыс.
The Best Way To Run Database Migrations in .NET
11:40
.NET 8 Is Now Available on AWS Lambda
7:10
Просмотров 1,7 тыс.
Reviewing your "Best Practices" in C#
12:14
Просмотров 31 тыс.
"I Lost a Job Because of This Codebase"
14:08
Просмотров 60 тыс.
The New .NET 9 HybridCache That You Must Upgrade To!
14:34