Skip to main content

Command Palette

Search for a command to run...

AWS Day 34: Create an AWS Lambda Function Using AWS CLI | KodeKloud 100 Days of Cloud

Updated
4 min readView as Markdown
AWS Day 34: Create an AWS Lambda Function Using AWS CLI | KodeKloud 100 Days of Cloud
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

Introduction

After creating a Lambda function using the AWS Management Console in the previous lab, Day 34 focused on deploying the same serverless application using the AWS Command Line Interface (AWS CLI).

In real-world DevOps environments, infrastructure is rarely created manually through the console. Instead, engineers automate deployments using tools such as the AWS CLI, Terraform, CloudFormation, or CI/CD pipelines.

This lab introduced the complete workflow of creating a Lambda deployment package, uploading it through the AWS CLI, and invoking the function—all without opening the AWS Console.

Why Use AWS CLI for Lambda?

While the AWS Console is useful for learning and quick testing, the AWS CLI offers several advantages:

  • Faster deployments

  • Easy automation in CI/CD pipelines

  • Scriptable infrastructure

  • Consistent deployments across environments

  • Better integration with Infrastructure as Code (IaC)

Using the AWS CLI is an essential skill for DevOps and Cloud Engineers managing serverless applications at scale.

Lab Objective

The objective of this lab was to:

  • Create a Python script named lambda_function.py

  • Package the script into function.zip

  • Create a Lambda function named nautilus-lambda-cli

  • Use the Python runtime

  • Attach the existing IAM role lambda_execution_role

  • Verify the Lambda function by invoking it through the AWS CLI

Step 1: Create the Python Lambda Function

I first created a file named lambda_function.py with the following code:

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

This simple Lambda function returns an HTTP status code of 200 along with a custom welcome message.

Step 2: Package the Function

AWS Lambda requires the source code to be uploaded as a ZIP archive.

I packaged the Python file using the following command:

zip function.zip lambda_function.py

This created a deployment package named:

function.zip

which was later uploaded to AWS Lambda.

Step 3: Verify the AWS Account

Before creating the Lambda function, I verified that my AWS CLI was authenticated by checking the active AWS account.

aws sts get-caller-identity

The command returned the current AWS Account ID and IAM user details, confirming that the CLI was configured correctly.

Step 4: Create the Lambda Function Using AWS CLI

Next, I created the Lambda function directly from the command line.

aws lambda create-function 
--function-name nautilus-lambda-cli 
--runtime python3.9 
--role arn:aws:iam::<ACCOUNT_ID>:role/lambda_execution_role 
--handler lambda_function.lambda_handler 
--zip-file fileb://function.zip

Command Breakdown

Parameter Description
--function-name Name of the Lambda function
--runtime Python runtime
--role IAM execution role
--handler Entry point of the Python function
--zip-file Deployment package

After a few seconds, AWS returned the Lambda function details, confirming that the function had been created successfully.

Step 5: Invoke the Lambda Function

Finally, I tested the function directly from the command line.

aws lambda invoke \
    --function-name nautilus-lambda-cli \
    response.json

The CLI returned:

What I Learned

This lab helped me understand how Lambda deployments are automated using the AWS CLI instead of the AWS Management Console.

Some of my key takeaways were:

  • How to package Lambda code into a ZIP archive.

  • How to authenticate and verify AWS CLI credentials.

  • How to create Lambda functions using command-line commands.

  • How IAM execution roles are attached during deployment.

  • How to invoke and test Lambda functions directly from the terminal.

These are the same concepts commonly used in DevOps automation and CI/CD pipelines.

Conclusion

Day 34 introduced a more practical approach to deploying serverless applications by using the AWS CLI instead of the AWS Management Console.

From writing the Python function and packaging it into a deployment ZIP file to creating and testing the Lambda function entirely through the command line, this lab demonstrated how serverless deployments can be automated efficiently.

As applications grow and deployments become more frequent, using tools like the AWS CLI becomes an essential skill for every DevOps and Cloud Engineer.

A

Thank you so much for this insightful post yet again Anand. Greatly appreciate this series.

100 Days Of Cloud (AWS)

Part 1 of 28

This series documents my 100 Days of Cloud journey with AWS using KodeKloud. Each blog covers one daily task with hands-on practice, simple explanations, and real learning for beginners and cloud aspirants.

Up next

AWS Day 33: Create a Lambda Function | KodeKloud 100 Days of Cloud

Introduction As cloud applications continue to evolve, serverless computing has become one of the most popular ways to build scalable applications without managing servers. Instead of provisioning EC2

More from this blog

A

Anand Raval

130 posts

I'm Anand Raval, a Cloud & DevOps Engineer with AWS Solutions Architect Associate (SAA-C03), Certified Kubernetes Administrator (CKA), and Azure Fundamentals (AZ-900) certifications. This blog covers AWS, Kubernetes, Terraform, CI/CD, cloud architecture, automation, cost optimization, troubleshooting guides, and hands-on DevOps projects.