Creating AWS Lambda function using AWS Console in python 3.0
AWS Lambda function is heavily used everywhere due to its server less functionality.
Today we will try to create a sample Hello World Lambda function in python.
First login to AWS Console and search for AWS Lambda Service as below from Search Bar-
Next Create a Lamba Function as below.
For now we will go for most basic function and select the Hello World template -
Give the details as below -
Name of the Lambda function -> hello-world-python3
Runtime -> Select Python 3.9
Permissions -> Select “Create New Role with Basic Lambda permissions” and press on “Create Function” button.
Lambda Function console will look like below
Now we will modify the lambda code with below code snippet-
def lambda_handler(event, context):
if(event[“place”] == “Hill” ):
return “My Dear friend lambda takes you to Hill. Welcome to Hill Station”
if(event[“place”] == “Ocean” ):
return “My Dear friend lambda takes you to Ocean. Welcome to Ocean”
if(event[“place”] == “Desert” ):
return “My Dear friend lambda takes you to Desert. Welcome to Desert”
if(event[“place”] == “Home”):
return “My Dear friend lambda takes you to Home. Welcome Back to Home”
Now configure test event for it as below -
Set the value for testevent as below and click on Create Event button -
{
“name”: “Hill”
}
Now let us deploy the lambda function just clicking on Deploy Button.
Now time to test by just pressing the test button above.
Now once you are done with your experiment you can delete the lambda function from console.
Step 1: Delete Lambda function from Console.
Go to Function. Select the corresponding Lambda function you want to delete and delete the Function.
Step 2: Delete role for Lambda function from Console.
So with minimum effort we have run a python code using Lambda through AWS Console.
No setup of python runtime and installation of python in machine, we just use the AWS lambda server less infrastructure to run Lambda Function.
Happy Reading!! Happy Coding!!