Skip to main content

Command Palette

Search for a command to run...

Day 33: Create a Lambda Function

Published
โ€ข2 min readโ€ขView as Markdown
Day 33: Create a Lambda Function
T

Cloud & SRE specializing in AWS and DevOps. I share my ongoing learning journey through practical tutorials and insights. Let's grow together.

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.

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

Image description

Permissions

Attach policy:

โœ… AWSLambdaBasicExecutionRole

Click Next

Image description

Role name

Role name:

lambda_execution_role

Click Create role

Image description

โœ… 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

Image description

๐Ÿ”น 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

Image description

๐Ÿ”น Step 4: Test the Lambda Function

Click Test

Create a new test event:

Event name: test

Keep default JSON

Click Test

Image description

Image description

โœ… 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.

More from this blog

W

Whispering Cloud Insights

88 posts

Documenting my path to cloud journey. Sharing lessons, tutorials, and insights from my continuous learning journey. Learn with me.