DEV Community

Cover image for Getting Started with AWS Lambda: Building Serverless Functions
Jyoti Bhasin
Jyoti Bhasin

Posted on • Updated on

Getting Started with AWS Lambda: Building Serverless Functions

AWS Lambda is a convenient compute service offered by Amazon Web Services (AWS) that allows you to execute your code without the hassle of provisioning or managing servers.

Image description

In this tutorial, we will guide you through the process of creating your initial serverless function using AWS Lambda.

Prerequisites-

  1. If you don't have an AWS account yet, you can easily create a free account at: https://aws.amazon.com/free/.

  2. Once you've created your account, simply log in to the AWS Management Console at: https://console.aws.amazon.com/.

Creating your first Lambda function

  • Open the AWS Management Console and navigate to the Lambda service.

Image description

Image description

  • Click on Create Function to initiate the creation of a new Lambda function.

Image description

  • Choose a blueprint that suits your specific use case. For instance, let's select the "hello world python" blueprint.

Image description

Configure function details:

  • Give your function a name, for example- MyFirstLambdaFunction.
  • Choose the runtime as Python 3.8 (or any other runtime)

Image description

Leave the permissions settings as the default values for now.

  • In the Function code section, you'll see the default code and you need to replace the code with the following snippet:
def lambda_handler(event, context):
    name = event['name']
    message = f"Hello, {name}!"
    return {
        'statusCode': 200,
        'body': message
    }

Enter fullscreen mode Exit fullscreen mode

Image description

  • Configure the test event: Under the Configure test events dropdown, select Hello-World as the sample event template.

  • Click on Create to create your Lambda function.

Testing the Lambda function

  • Once your function is created, you can test it by clicking on the Test button in the Lambda function console.

Image description

  • Select the HelloWorld test event from the dropdown and click on Test again.

  • You should see the output of your Lambda function in the console, which should be a JSON object containing the greeting message.

Image description

What do you think about AWS Lambda?

Top comments (2)

Collapse
 
chandug25 profile image
Chandra Sekhar G

"That's amazing, Jyoti Bhasin! You explained it straightforwardly and simply. I will definitely give it a try soon. Thank you for your insightful blogs. I am eagerly looking forward to reading more from you."

Collapse
 
secure_bug profile image
Jyoti Bhasin

Thank you :)