In this article, I will show you how you can create a lambda function in AWS using serverless framework.
Table of Contents
What is Lambda function?
AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that code. It was introduced in November 2014. Wikipedia
Why it matters to you?
Because, lambda is serverless, which means you don’t need to manage any kind of server to run your code. So you write your code and push to lambda function and then click Execute, which will then eventually execute your code instantly. It means you don’t need to set up a web-server and install dependencies for hours to just run your code. It gives an option to run your code on the fly. Even you can trigger lambda with different events from other aws services like S3, SQS or EC2, etc. The billing process of Lambda is also interesting, which is, pay as long as this function takes time to execute. So for example, if the Lambda function takes 3 minutes to execute then I will be charged for only 3 mins of execution, which is really great for startups. You can use lambda to run different microservices so that your application becomes distributed rather than monolithic.
How to create a Lambda
The steps required to create a AWS Lambda function using server is given below.
Install serverless framework
I have installed ServerLess using NPM. If you want to know how to install NPM please check out my this video here.
npm install -g serverless
This command above will install a serverless framework for you on your Linux machine.
Then Create an IAM user for serverless.
3. Next Configure aws API key and secret into aws-cli.
4. After that, Create a project using serverless.
5. Next, Modify the serverless.yml file based on your choice.
6. Then, Deploy this function to aws.
7. When it’s deployed, you can view the newly created stack in cloud-formation.
8. Then, Execute the lambda function and view logs in cloud-watch.
Looking for more articles on DevOps, checkout my DevOps related articles here.