Read/Write to Disk: There are a few things to wrap your head around regarding serverless architectures in general. There's no persistent storage because it is essentially a container. You have a tiny /tmp dir where you can write to disk, but you seriously do not want to.
DB: You have to use a database which is hosted separately. You can, of course, spin up a server and host it yourself, but that's too painful for me so I just use DBaaS solutions such as MongoDB Atlas or AWS RDS. But you can use whatever you like here pretty much. I explained hooking up Atlas to Lambda here.
Free tiers: AWS Lambda's free tier is only about invocations and compute time. The performance and start-up speeds are the same nevertheless. Lambda cold starts are usually between 1 and 3 seconds. Which is manageable if you use warm-up scripts and proper tooling. I'd suggest you do use the Serverless Framework and some monitoring solution like Dashbird if you want to create production apps. Take a look at the articles covering all things tagged #serverless on my profile
Other FaaS solutions: AWS Lambda is by far the most used and covers most languages. But Google Cloud Functions (Firebase Functions) are great as well. Of course Azure has their Functions too. All of those get the job done the same way. Even the pricing is literally the same. It all boils down to which provider you use and you pick your FaaS solution based on that.
Great Adnan...Clear Explanation on what to do with AWS Lamdba...one question , is that possible to stop the api gateway which we created for roll-a-dice temporarily, if so how could I do it?....
Do we need to include the node_modules folder when we upload the zip to lambda?
You can't "stop" the API Gateway entirely, but you can add an API Key to rate-limit the endpoint.
Yes, you need to include the node_modules. I tend to write Lambda code locally and use the Serverless Framework to deploy the code and resources. Check out this article I wrote to learn how.
The upload zip instructions don't make sense. If I run mkdir roll-a-dice && npm init -y then the node_modules directory will be outside my project directory and will not be include in the zip.
That's actually a great question. I haven't tried it yet, but I'd say it's better to use nuxt generate and host static content on S3. If you get around to trying it, feel free to get in touch with me!
Awesome article, thanks for writing! I've been trying to learn AWS lambda recently, but I find the official docs rather confusing, this article helped a lot!
Nice article. It would also be interesting to talk about receiving input to the lambda handler. I see the event argument is passed into the function but it's never used.
Nice one, Adnan. I'm bookmarking this article.
It would be interesting to know about a couple more things:
Thanks! Glad you're interested in learning more.
/tmpdir where you can write to disk, but you seriously do not want to.Hope this clears things up. :)
Awesome, thank you! :D
Thats a very nice article Adnan. I'm looking to find a way to write Lambda code in local IDE so that I can have version control. Any suggestions?
I use VSCode and the Serverless Framework to manage my resources and code. Check out this article I wrote to learn how.
Great Adnan...Clear Explanation on what to do with AWS Lamdba...one question , is that possible to stop the api gateway which we created for roll-a-dice temporarily, if so how could I do it?....
Do we need to include the node_modules folder when we upload the zip to lambda?
You can't "stop" the API Gateway entirely, but you can add an API Key to rate-limit the endpoint.
Yes, you need to include the
node_modules. I tend to write Lambda code locally and use the Serverless Framework to deploy the code and resources. Check out this article I wrote to learn how.The upload zip instructions don't make sense. If I run mkdir roll-a-dice && npm init -y then the node_modules directory will be outside my project directory and will not be include in the zip.
Oh, that's a typo. Thanks for noticing Dan! I've fixed it now.
great explanation!!! :D
Glad you liked it!
Hi Adnan,
Can you tell me how to host nuxt js server in lambda?
That's actually a great question. I haven't tried it yet, but I'd say it's better to use
nuxt generateand host static content on S3. If you get around to trying it, feel free to get in touch with me!Awesome article, thanks for writing! I've been trying to learn AWS lambda recently, but I find the official docs rather confusing, this article helped a lot!
Glad it helped! I can understand the pain of reading the AWS docs. They are surprisingly bad for such a huge provider.
Nice article. It would also be interesting to talk about receiving input to the lambda handler. I see the event argument is passed into the function but it's never used.
Thanks! :)
Here's another article I wrote a while back.
A crash course on securing Serverless APIs with JSON web tokens
Adnan Rahić
It's a bit more detailed, with examples of receiving input. :)
I assumed you wanted us to cd into 'roll-a-dice' directory and do an 'npm install moment --save' (for the uploading zip folder part).
adnan excelente articulo lo lei y me quedo mucho mas claro aws lambda si tubiera mas informacion y la puedes compartir seria de gran utilidad
saludos