-->
AWS Lambda is a serverless computing service provided by AWS. It is a service that runs your code in response to an event and automatically manages the resources required for running your code. You don't need to worry about any underlying resources which are required.
Implementing real-time data streaming from a server to a client can be challenging, especially when working with APIs that return data in chunks. Let me share a story of how I tackled this problem while using Python Flask for the backend and Vue.js with the Quasar framework for the frontend. It was a journey filled with trials, errors, and some exciting discoveries.
Agentic AI is quickly becoming a buzzword in the world of technology, and for good reason. Imagine AI agents capable of thinking, planning, and executing tasks with minimal human input—this is the promise of Agentic AI. It’s a revolutionary step forward, allowing businesses to operate smarter, faster, and more efficiently.
In the world of big data, efficient management and analysis of large datasets is crucial. Amazon S3 Tables offer a fully managed solution built on Apache Iceberg, a modern table format designed to handle massive-scale analytical workloads with precision and efficiency.
How can businesses identify untapped opportunities, improve efficiency, and design more effective marketing campaigns? The answer lies in leveraging the power of data. Today, data analytics isn’t just a support function—it’s the backbone of decision-making. When combined with Artificial Intelligence (AI), it transforms how companies operate, enabling them to predict trends, optimize operations, and deliver better customer experiences.
AWS Lambda is a serverless computing service provided by AWS. It is a service that runs your code in response to an event and automatically manages the resources required for running your code. You don't need to worry about any underlying resources which are required.
One example of such an event is a file uploaded to the S3 bucket. You can trigger your lambda function when the file is uploaded to your S3 bucket. You can think of a data processing job where files are being uploaded to your bucket and you want to start processing as soon as files arrive in the bucket. This will help you achieve real-time data processing use cases.
Now that you know what the AWS lambda function is, let's create our first Lambda function.
Create the file named app.py and include the following code in it.
# This is a handler
def handler_name(event, context):
# Your logic
return True
You must be wondering what is handler_name function. Basically, the handler function is a method in your code that processes events. When you invoke your lambda function, lambda runs your handler method. For example, if you have configured an event for triggering the lambda function on file upload in an S3 bucket, upon successful upload of the file in a bucket, Lambda will run your method named handler_name .
Now that we know what the handler is, we need to know how we define the handler's name. It depends on 2 things.
For example, the filename is app.py and the method name is lambda_handler , your lambda handler name will be app.lambda_handler .Basically filename.handler_method_name
When your Lambda function is invoked, lambda passes 2 arguments to your handler function. event and context (Lambda context)
Let's assume event data is {first_name: "Mayank", last_name: "Patel"} . Now update your lambda_handler with the following code.
def lambda_handler(event, context):
message = 'Hello {} {}, this is from Lambda Function!'.format(event['first_name'], event['last_name'])
return {
'message' : message
}
Now, we need to build the deployment package.
Open your terminal and run the following commands
Let's update the handler method with the following content which has a dependency on python requests library
import requests
def lambda_handler(event, context):
response = requests.get("https://www.example.com/")
print(response.text)
return response.text
Now, open your terminal and run the following commands.
After following the above steps, now you have your lambda deployment package ready locally. Now, it's time to deploy this package.
Follow the below steps to deploy your local lambda package.
There are 2 ways you can deploy your lambda function. Using AWS CLI or from the console.
Here, I assume you have configured AWS CLI.
Please create the execution policy. It gives your lambda function access to AWS resources.
aws iam create-role --role-name lambda-ex --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}
Now, you need to add permission to your role
aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Now, run the below command to deploy your package.
aws lambda create-function --function-name my-function --zip-file fileb://lambda_deployment_package.zip --handler app.lambda_handler --runtime python3.9 --role arn:aws:iam::123456789012:role/lambda-ex
Here, replace 123456789012 with your AWS Account ID. You can get it by logging into the AWS console and clicking on your name in the top-right corner.
Please follow the below steps to deploy your lambda function
Now, you can test your lambda function. However, there are some key settings that you may want to set for your function.
To test your newly deployed serverless lambda function, head to the Test sub-tab.
You can either Save your Test event by giving the name and providing input to Event JSON if applicable and hit Save.
If you don't want to Save and just want to Test, hit Test after giving input to Event JSON.
So far, I have covered basic lambda function package preparation, deployment, and setting key configuration.
So far I have covered the basics of AWS lambda which include writing Lambda handler method, preparing lambda package with and without dependencies, and deploying lambda function using AWS CLI and from AWS Console.