lrpc

package module
v0.0.0-...-0821f6f Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2018 License: MIT Imports: 0 Imported by: 0

README

LRPC

AWS Lambda net/rpc server, client via AWS API.

The packages provided are intended to allow deploying net/rpc services to AWS Lambda and calling them with net/rpc Client conventions or via a JSON-RPC 1.0 payload.

Server

Servers use Register or RegisterName from lrpc/server, or RPCServer to set the net/rpc server to serve. The server.Serve() function is then called from a main package. Deploying such main packages is facilitated with lago.

Client

Clients access net/rpc servers running as Lambda handlers via the lrpc/client package. Call (and Invoke) issues the request via the AWS Lambda API.

Demo

See the demo package.

How it works

The server inspects the payload and handles the request as gob-encoded or a JSON-RPC 1.0

With client package

The client gob-encodes an rpc.Request and request body to the Invoke payload. The server invokes the rpc.Request with the supplied body. If a method error occurs, it is encoded as a rpc.Response. Otherwise, the response body is also encoded.

With JSON-RPC

The JSON-RPC request is sent as a Lambda payload directly, either via REST call or any AWS SDK. The "id" field of the request may be of any type. If the "id" is null or omitted, the output of any method call is discarded. Otherwise, the "id" field as supplied will be returned with the response. Method call output is marshalled to the "result" field. If an error occurs or a panic is recovered at any point in the Lambda invocation, the "error" field will be populated with a message and the "result" field will be null. All marshalling and unmarshalling is by the json package's conventions.

Notes

The Lambda environment must be considered stateless (unless you're aware of how it isn't and design your net/rpc service accordingly). If a server cannot decode a request (which should be impossible), an out-of-band error occurs. In-band errors use a unique convention: errors returned by a method invocation append a newline followed by the request ID, errors and panics that occur before or after a method invocation append a tab character followed by the request ID. The intent is not nessisarily for clients to inspect returned delimiters but provide additional information in a unique way when read by a human. Errors returned by the client (in general due to invalid invocation) are unadorned.

The lh package makes it easy to serve (many or most) http.Handlers with the AWS Lambda Go runtime. The lago tool makes it easy to deploy Go handlers to the Lambda Go runtime.

Documentation

Overview

Package lrpc contains clients and servers for net/rpc on AWS Lambda.

The lrpc/server package is intended to replace net/rpc for types that implement rpc.Server method sets. Main packages that call lrpc/server.Serve may be used as Lambda handlers. The https://github.com/cloudinterfaces/lago tool may be used to deploy such main packages.

The lrpc/client package contains functions to call net/rpc services deployed to Lambda functions with the lrpc/server package.

The lrpc/demo package contains a net/rpc service and client wrapper, as well as main packages that exercise both.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestID

func RequestID(err error) string

RequestID returns the request ID associated with err or *unknown* if it cannot be determined.

Types

type ID

type ID string

ID is a Lambda Request ID.

func (ID) RequestID

func (i ID) RequestID() string

RequestID returns the request ID.

type LambdaError

type LambdaError struct {
	ErrorMessage string
	ErrorType    string
}

LambdaError is a structured error returned by a Lambda invocation.

func (LambdaError) Error

func (l LambdaError) Error() string

Error implements Error.

type MethodError

type MethodError struct {
	Err string
	ID
}

MethodError is an error returned by an rpc method invocation.

func (MethodError) Error

func (m MethodError) Error() string

Error implements error.

type ServerError

type ServerError struct {
	Err string
	ID
}

ServerError is an error scoped to the server package.

func (ServerError) Error

func (e ServerError) Error() string

Error implements error.

Directories

Path Synopsis
client command
server command
Package inspect allows inspection of Lambda function invocations.
Package inspect allows inspection of Lambda function invocations.
internal
Package server allows rpc/server implementations to be deployed to AWS Lambda.
Package server allows rpc/server implementations to be deployed to AWS Lambda.

Jump to

Keyboard shortcuts

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