In the past, if you needed to run a service in your company, it was necessary to have the hardware and software infrastructure required. But what happens when you are faced with scaling up or scaling down? If you want to scale up, then you need more servers and more space for storage. And if there is an issue with one of those components, then all of your services will be affected.
With AWS Lambda though, there’s no need for any of that because this service runs on Amazon Web Services (AWS) It provides compute power without provisioning or managing anything—you just upload your code and they take care of everything else! This means that services can be scaled up or down as needed without any downtime which is great for companies.
With Amazon Web Services’ Lambda, you can run your code on their infrastructure without having to manage anything yourself! In this blog, we’ll introduce what lambda is, how it works. So, let’s get started!!
SERVERLESS, what does it mean?
When you hear the term “Serverless Architecture”, what do you think about it? You might imagine an architecture where no servers are involved, and everything is taken care of for us. While this isn’t exactly true–there still are some server components in a Serverless environment that we don’t have to worry about because they’re handled by Amazon or another provider (AWS).
This means AWS handles all our infrastructure needs so we can focus on building out great applications!
What is AWS Lambda?
AWS Lambda is a service provided by Amazon Web Services (AWS). AWS Lambda helps you create self-contained programs in one of the many languages and runtimes, which you can then upload to AWS. These programs can do any kind of computing task, like serving web pages or processing streams of data. The point is that an AWS Lambda program does not need its own servers to run them on.
Working of AWS Lambda?
Source : https://aws.amazon.com/lambda/
Lambda allows you to run your code whenever an event occurs. For example, let’s say that I have a website and want it to automatically tweet out the number of new users who sign up every day. Rather than having my own developers write something for this, we could use Lambda because all we would need is a single line of code in order for our site URL to be sent off with each user account creation!
Lambda provides many different methods of writing your code. You can write in the Lambda UI, or you can use an external editor and upload it to their servers for processing.
After you have written code, customize your configuration with the amount of memory and max execution time. You can also integrate your function with various AWS services like S3, DynamoDB, Kinesis, SNS, etc.
When your event occurs, your function runs and executes the code in it then shuts off to wait for another time.
Lambda pricing is based on the number of requests, which cost 20 cents per 1M and their duration. It also has a free tier of up to 400,000 GB-seconds/month when you use it for under 1M requests or so with the first million being free as well every month.
AWS Lambda Pricing
AWS Lambda pricing is based on the number of requests made. For every million requests, it costs you nothing, and after that monthly fee starts at US$20/million (or GB seconds). You can choose between memory allocation which ranges anywhere from 1GB up to 3.2M+ thousand MBs per month – this will depend entirely on what sorta load your function might be under; there are also other variables like duration in terms an amount used as well so don’t worry if something doesn’t make sense right away!
Let’s Take a deep dive into Lambda
- Sign in to AWS management console and in search type “lambda”
- The dashboard will appear and click on Create Function.
- We are offered 4 options and we are going to use a blueprint
- Select Use a blueprint
- Then in the blueprints just type hello and select hello-world-python
- Click on it and click on configure.
- Give Function name as “demo-lambda”
- In the lambda execution role leave it as the default option
- Scroll down and you will see the code which will be imported for our lambda function
- So, this is going to be the lambda handler and it will print 3 logs and return one value
- Click on Create Function
- Our function is created and we will be able to run it now
- Below is the Code source if you click on lambda function.py you will see the function is now loaded into the code editor
- Now we will go ahead and test our function
- Click on Test.
- We need to create a new test event which is a hello-world event that contains code as a JSON document
- Give the Event name as DemoEvent and click on Create.
- You will the DemoEvent as successfully created and again click on Test
- The Execution result will show the response as just like the lambda function
- So, from the Developers’ perspective if you see then the code is uploaded into the lambda code editor and it is run by lambda very quickly and we didn’t deploy any servers.
- So, some fewer things if you want to check out scroll down and see Runtime settings we are running Python 3.7, and the function is lambda_function.lambda_handler.
- If you click on the Configuration tab and then click on Permissions you will see the Role name that was created for us by the lambda console.
- Above is the Resource summary, you can see CloudWatch logs has 3 actions and 2 resources which allow us to create LogGroup and LogStream and also send logs to CloudWatch Logs.
- So, this is the whole idea behind this Permissions tab.
AWS knowledge is helpfull for high paying career. Explore our more resources to get trained for AWS career.
- Explore AWS Route 53 interview questions.
- Practice for your interview with AWS live project training.
- Read top AWS IAM interview questions.
- Read concepts of data ingestion in AWS.
- Read top EC2 interview questions and answers.
Lambda is a convenient, cost-effective way to run your code in the cloud. With it, you can be flexible and use its features for many situations such as running unit tests or creating Slack notifications when an object has been created.
Discover more about AWS in our other blog post.
No comment yet, add your voice below!