caddyawslambda

package module
v0.0.0-...-78dd2d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

caddy-awslambda

Caddy v2 module for dispatching requests to AWS Lambda.

This is a port of https://github.com/coopernurse/caddy-awslambda with less features but for Caddy 2.

Installation

xcaddy build \
    --with github.com/floj/caddy-awslambda

Usage

{
  order awslambda before file_server
}

http://localhost:8080 {
  log {
    output stderr
  }
  awslambda /services/* {
    function ForwardToSlack
  }
}

License

Apache 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LambdaMiddleware

type LambdaMiddleware struct {
	FunctionName string `json:"function,omitempty"`
	Timeout      string `json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

LambdaMiddleware implements an HTTP handler that invokes a lambda function

func (*LambdaMiddleware) CaddyModule

func (*LambdaMiddleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*LambdaMiddleware) Cleanup

func (m *LambdaMiddleware) Cleanup() error

Cleanup implements caddy.Cleanup TODO: ensure all running processes are terminated.

func (*LambdaMiddleware) Provision

func (m *LambdaMiddleware) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*LambdaMiddleware) ServeHTTP

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*LambdaMiddleware) UnmarshalCaddyfile

func (m *LambdaMiddleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile configures the global directive from Caddyfile. Syntax:

awslambda [<matcher>] {
    function <function name>
    timeout  <duration>
}

func (*LambdaMiddleware) Validate

func (m *LambdaMiddleware) Validate() error

Validate implements caddy.Validator

type Reply

type Reply struct {
	// Must be set to the constant "HTTPJSON-REP"
	Type string `json:"type"`
	// Reply metadata. If omitted, a default 200 status with empty headers will be used.
	Meta *ReplyMeta `json:"meta"`
	// Response body
	Body string `json:"body"`
	// Encoding of Body - Valid values: "", "base64"
	BodyEncoding string `json:"bodyEncoding"`
}

Reply encapsulates the response from a Lambda invocation. AWS Lambda functions should return a JSON object that matches this format.

type ReplyMeta

type ReplyMeta struct {
	// HTTP status code (e.g. 200 or 404)
	Status int `json:"status"`
	// HTTP response headers
	Headers map[string][]string `json:"headers"`
}

ReplyMeta encapsulates HTTP response metadata that the lambda function wishes Caddy to set on the HTTP response.

*NOTE* that header values must be encoded as string arrays

type Request

type Request struct {
	// Set to the constant "HTTPJSON-REQ"
	Type string `json:"type"`
	// Metadata about the HTTP request
	Meta *RequestMeta `json:"meta"`
	// HTTP request body (may be empty)
	Body string `json:"body"`
}

Request represents a single HTTP request. It will be serialized as JSON and sent to the AWS Lambda function as the function payload.

type RequestMeta

type RequestMeta struct {
	// HTTP method used by client (e.g. GET or POST)
	Method string `json:"method"`

	// Path portion of URL without the query string
	Path string `json:"path"`

	// Query string (without '?')
	Query string `json:"query"`

	// Host field from net/http Request, which may be of the form host:port
	Host string `json:"host"`

	// Proto field from net/http Request, for example "HTTP/1.1"
	Proto string `json:"proto"`

	// HTTP request headers
	Headers map[string][]string `json:"headers"`
}

RequestMeta represents HTTP metadata present on the request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL