Learn SERVERLESS-FRAMEWORK with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Simple Serverless Function (Node.js)
# serverless/demo_nodejs/serverless.yml
service: hello-world
provider:
name: aws
runtime: nodejs14.x
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
# serverless/demo_nodejs/handler.js
'use strict';
module.exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello World' })
};
};
A simple Serverless Framework Node.js function responding to HTTP events.
2
Simple Serverless Function (Python)
# serverless/demo_python/serverless.yml
service: hello-world
provider:
name: aws
runtime: python3.9
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
# serverless/demo_python/handler.py
import json
def hello(event, context):
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello World'})
}
A simple Serverless Framework Python function responding to HTTP events.
3
Simple Serverless Function (Go)
# serverless/demo_go/serverless.yml
service: hello-world
provider:
name: aws
runtime: go1.x
functions:
hello:
handler: bin/handler
events:
- http:
path: hello
method: get
# serverless/demo_go/handler/main.go
package main
import (
"context"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "Hello World",
}, nil
}
func main() {
lambda.Start(handler)
}
A simple Serverless Framework Go function responding to HTTP events.
4
Simple Serverless Function (Java)
# serverless/demo_java/serverless.yml
service: hello-world
provider:
name: aws
runtime: java11
functions:
hello:
handler: com.example.Handler::handleRequest
# serverless/demo_java/src/main/java/com/example/Handler.java
package com.example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import java.util.Map;
public class Handler implements RequestHandler<Map<String,Object>, String> {
@Override
public String handleRequest(Map<String,Object> input, Context context) {
return "Hello World";
}
}
A simple Serverless Framework Java function responding to HTTP events.