greenpau / caddy-lambda

Event-Based Function Execution (Lambda) Plugin for Caddy v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

caddy-lambda

Event-Based Function Execution (Lambda) Plugin for Caddy v2.

Table of Contents

Overview

The caddy-lambda triggers execution of a function when it is invoked. It is a terminal plugin, i.e. the plugin writes response headers and body.

Getting Started

The Caddyfile config follows:

localhost {
	route /api/* {
		lambda {
			name hello_world
			runtime python
			python_executable {$HOME}/path/to/venv/bin/python
			entrypoint assets/scripts/api/hello_world/app/index.py
			function handler
		}
	}
	route {
		respond "OK"
	}
}

The assets/scripts/api/hello_world/app/index.py follows:

import json

def handler(event: dict) -> dict:
    print(f"event: {event}")
    response = {
        "body": json.dumps({"message": "hello world!"}),
        "status_code": 200,
    }
    return response

The response dictionary is mandatory for a handler. he status_code and body are mandatory fields of the response. The plugin writes status_code and body back to the requestor.

About

Event-Based Function Execution (Lambda) Plugin for Caddy v2

License:Apache License 2.0


Languages

Language:Go 86.2%Language:Makefile 11.0%Language:Python 2.8%