What is AWS Lambda and how to use it ??

  • Lambda is a function as a service (FAAD) provides by Amazon.
  • It is a serverless service.
  • It charges for per ms.
  • It is free for 1milllion request
  • Bydefault lambda service have permission to upload logs in cloud watch.

How to use lambda service:

  1. Click on create function
  2. Select one option for creating function their is option for creating function from scratch, we can use blueprint or can another option.
  3. Then give a function name
  4. Select a run time (programming language).
  5. Then we can attach a role to lambda service if lambda need to use another servise. Bydefault lambda service have a role which have permission to upload logs in cloud watch.
  6. Then click on create function.

7. It will create a function after these scroll down and here we can write our function after creating a .py file. In a function it is compulsary to give two parameters. One for receiving new data (events) and second Second for reference(context). As we have deleted the default file so change the handler to prog.f1.

We use events and context as parameter names. i.e def (events,context,):

  • deploy:

If you change any thing in function to save changes click on deploy and then test function.

  • Handler:

In lambda we can only run one function at a time if we have multiple function then to run single function use hander.

give hander as <program_fileName>.<function_name>

Eg. -> prog.f1

To use handler, scroll down and click on edit runtime setting then give handler.

Bydefault Maximum time a function can run in lamda is 3 sec. we can change it to max 15 min.

Eg.

import time
def f2(events,context):
time.sleep(5) //it will run the function more than 5 min
print(“Function two”)

It will give error of time out.

To change default time out:

Go to basic settings click on edit.

Now you can run a function more than 3 sec.

Thank you for reading.