DEV Community

Cover image for Day 33: Create a Lambda Function
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 33: Create a Lambda Function

Lab Information

The Nautilus DevOps team is embracing serverless architecture by integrating AWS Lambda into their operational tasks. They have decided to deploy a simple Lambda function that will return a custom greeting to demonstrate serverless capabilities effectively. This function is crucial for showcasing rapid deployment and easy scalability features of AWS Lambda to the team.

Create Lambda Function: Create a Lambda function named nautilus-lambda.

Runtime: Use the Runtime Python.

Deploy: The function should print the body Welcome to KKE AWS Labs!.

Status Code: Ensure the status code is 200.

IAM Role: Create and use the IAM role named lambda_execution_role.
Enter fullscreen mode Exit fullscreen mode

Use the AWS Console to complete this task.

Lab Solutions

πŸ”Ή Step 1: Create the IAM Role (lambda_execution_role)

Go to AWS Console β†’ IAM

Click Roles β†’ Create role

Trusted entity type:

Select AWS service

Use case:

Choose Lambda

Click Next

Permissions

Attach policy:

βœ… AWSLambdaBasicExecutionRole

Click Next

Role name

Role name:

lambda_execution_role

Click Create role

βœ… IAM role is ready.

πŸ”Ή Step 2: Create the Lambda Function

Go to AWS Console β†’ Lambda

Click Create function

Choose Author from scratch

Basic information

Function name:

nautilus-lambda

Runtime:

Python (Python 3.x – any available version is fine)

Permissions

Under Change default execution role

Select Use an existing role

Choose:

lambda_execution_role

Click Create function

πŸ”Ή Step 3: Add the Lambda Function Code

In the Code tab, replace the default code with this:

def lambda_handler(event, context):
return {
"statusCode": 200,
"body": "Welcome to KKE AWS Labs!"
}

Click Deploy

πŸ”Ή Step 4: Test the Lambda Function

Click Test

Create a new test event:

Event name: test

Keep default JSON

Click Test

βœ… Expected Output

You should see:

{
"statusCode": 200,
"body": "Welcome to KKE AWS Labs!"
}


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)