• Devops Diaries
  • Posts
  • [Hands- On] AWS Lambda: Build & Deploy Your First Function

[Hands- On] AWS Lambda: Build & Deploy Your First Function

As part of AWS Hands-on Topics covering all major AWS services, today will start withAWS Lambda: Build & Deploy Your First Function.

Hands-on AWS content is highly valuable for practical learning.
As part of AWS Hands-on Topics covering all major AWS services, today will start with …

AWS Lambda: Build & Deploy Your First Function.

Step 1: Prerequisites

Before starting, ensure to have:
✅ An AWS Free Tier account
✅ AWS CLI installed and configured (aws configure)
✅ IAM user with Lambda permissions
✅ Node.js or Python installed (for function development)

Step 2: Create an IAM Role for Lambda

AWS Lambda needs execution permissions.

1️⃣ Go to IAMRolesCreate Role
2️⃣ Select AWS serviceLambda → Click "Next"


3️⃣ Attach the following permissions:

AWSLambdaBasicExecutionRole

AWSLambdaVPCAccessExecutionRole (if using VPC)

4️⃣ Name the role (e.g., LambdaExecutionRole) and create it.

Step 3: Create an AWS Lambda Function (Console)

1️⃣ Open AWS Lambda in the AWS Management Console
2️⃣ Click Create Function
3️⃣ Select Author from Scratch
4️⃣ Function Name: hello-world-lambda
5️⃣ Runtime: Choose Python 3.13
6️⃣ Execution Role: Select the IAM Role created earlier
7️⃣ Click Create Function

Step 4: Write Your First Lambda Function

If using Python:

Replace the default code with:

import json

def lambda_handler(event, context):

return {

"statusCode": 200,

"body": json.dumps("Hello from AWS Lambda!")

}

Click Deploy

Step 5: Test Your Lambda Function

1️⃣ Click on Test

2️⃣ Configure a new test event with { "key": "value" }
3️⃣ Click Test again
✅ You should see "Hello from AWS Lambda!" in the response

Step 6: Clean Up Resources

To avoid unnecessary AWS charges: delete lambda function

CLI command:

aws lambda delete-function --function-name hello-world-lambda

𝘾𝒐𝙣𝒈𝙧𝒂𝙩𝒖𝙡𝒂𝙩𝒊𝙤𝒏𝙨! 𝒀𝙤𝒖 𝒋𝙪𝒔𝙩 𝙗𝒖𝙞𝒍𝙩 & 𝙙𝒆𝙥𝒍𝙤𝒚𝙚𝒅 𝒚𝙤𝒖𝙧 𝙛𝒊𝙧𝒔𝙩 𝘼𝑾𝙎 𝙇𝒂𝙢𝒃𝙙𝒂 𝒇𝙪𝒏𝙘𝒕𝙞𝒐𝙣!

Other things, we can do with AWS Lambda

Invoke Lambda Function via AWS CLI

Run the following command:

aws lambda invoke --function-name hello-world-lambda output.json

Check output.json to see the response.

Trigger Lambda with API Gateway

To invoke Lambda via HTTP:
1️⃣ Go to AWS API Gateway
2️⃣ Create a REST API
3️⃣ Create a new resource & method (GET)
4️⃣ Integrate it with Lambda Function
5️⃣ Deploy the API → Get the Invoke URL
6️⃣ Test via browser or Postman

Reply

or to participate.