Serverless Framework

Introduction
In this series, we’ll focus on Serverless Framework, one of the fastest ways to build and deploy serverless applications.
If you’ve already worked with Terraform, you know how great it is for infrastructure automation. So why another tool?
Because Serverless Framework is built specifically for deploying serverless apps — it abstracts away the heavy lifting of infrastructure management and lets you deploy complex setups in just a few lines of configuration.
Just like Terraform, Serverless is cloud-agnostic — it supports AWS, GCP, and Azure out of the box.
Setting Up
Refer to the official setup guide for installation instructions.
If you’re on Windows, consider using WSL (Windows Subsystem for Linux) — it makes development smoother and closer to a native Linux experience, especially when working with AWS or Python.
Once Serverless is installed, it can use your existing AWS CLI credentials automatically.
If you already have AWS CLI configured with a default profile, you don’t need extra setup.
However, if you haven’t configured AWS yet, here’s how:
Go to IAM → Users in AWS Console
Create a new user named
serverlessAttach the AdministratorFullAccess policy (for simplicity — use least privilege in production)
Create an Access Key and Secret Key
Configure credentials locally:
serverless --version
serverless config credentials --provider aws --key <yourKey> --secret <yourSecret>
Test Setup
To confirm everything works, let’s deploy a simple Lambda function.
Create a Test Project
serverless create --template aws-python --path new_project --name testFunc
This will generate a project structure like:
new_project/
├── handler.py
└── serverless.yml
Minimal serverless.yml
Remove comments to simplify it:
service: testFunc
frameworkVersion: '3'
provider:
name: aws
runtime: python3.8
functions:
hello:
handler: handler.hello
Deploy
Now deploy the function:
sls deploy
Once deployed, you’ll see a confirmation similar to this:
Deploying testFunc to AWS...
Service Information
stage: dev
region: us-east-1
stack: testFunc-dev
To remove everything later:
sls remove
🎉 Congratulations! You just deployed your first serverless function.
Invoking the Function
Testing locally or through the CLI is straightforward:
# Invoke and view output
sls invoke -f hello --log
# Stream recent logs
sls logs -f hello --tail
Sample Output
$ sls invoke -f hello --log
{
"statusCode": 200,
"body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
--------------------------------------------------------------------
START
END Duration: 1.33 ms (init: 130.95 ms) Memory Used: 38 MB
Using External Libraries
Most real-world Lambdas depend on external libraries (like pandas or requests).
Serverless makes it easy to package and deploy them in two ways:
Option 1 — Include Dependencies as a Zip
Bundle dependencies directly into your deployment zip.
Option 2 — Use Lambda Layers
Upload dependencies as a Lambda Layer to share across multiple functions.
Learn more: AWS Blog – Lambda Layers
Using the serverless-python-requirements Plugin
Install the plugin:
sls plugin install -n serverless-python-requirements
Then update serverless.yml:
Using Zip Packaging
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
zip: true
For zipped dependencies, include this at the top of your Python code:
import unzip_requirements
Using Lambda Layers
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
layer:
name: PandasLayer
Define dependencies in requirements.txt, for example:
pandas==1.0.1
Serverless will automatically build and deploy them as a Lambda Layer.
Summary
The Serverless Framework offers a fast, cloud-agnostic way to create and manage serverless applications.
It simplifies deployment, testing, and packaging, letting developers focus on code — not infrastructure.
👉 Check out the GitHub repository for examples:
github.com/k-pulkit/source-demo-serverless-framework





