Create your first lambda function

We will create a Lambda Function using Lambda console.

  1. On the console. Choose Services -> Lambda

2. In the Lambda console, choose Create a function.

3. Choose Author from Scratch.

4. For Name, type sum.

5. Set the Runtime to Python 3.9

6. Click Create function, and it will redirect to the setup page of Lambda function.

7. Copy the following Lambda function and paste it into the code editor in the Lambda console.

# define function handler with parameters "event" and "context"
# for details, please check https://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html

def sum(event, context): 
    a = float(event["a"])
    b = float(event["b"])
    
    c = a + b
    
    return {
        "c":c
    }

8. In Runtime settings, click Edit and change the handler to: lambda_function.sum. Remember to click Save button to save it.

9. Now the panel should look like the following fig. Choose Deploy.

Last updated