Documentation ¶
Index ¶
- Variables
- func NewRouter(conf *RouterConfig) *chi.Mux
- func Start(ctx context.Context, s settings.Source, f Fetcher) error
- func StartHTTP(ctx context.Context, s settings.Source, f Fetcher) error
- func StartHTTPMock(ctx context.Context, s settings.Source, f Fetcher) error
- func StartLambda(ctx context.Context, s settings.Source, f Fetcher, target string) error
- func StartLambdaMock(ctx context.Context, s settings.Source, f Fetcher, target string) error
- type Fetcher
- type Function
- type Invoke
- type LambdaFunction
- type LogFn
- type Logger
- type MockingFetcher
- type NotFoundError
- type RouterConfig
- type Stat
- type StatFn
- type StaticFetcher
- type URLParamFn
Constants ¶
This section is empty.
Variables ¶
var LambdaStartFn = lambda.StartHandler
LambdaStartFn is a reference to lambda.StartHandler that is exported for cases where a custom net/rpc server needs to run rather than the true native lambda server. For example, this project leverages this feature in our integration tests where we add some additional signal handling for testing purposes.
var LoggerFromContext = logevent.FromContext
LoggerFromContext extracts the current logger.
var StatFromContext = xstats.FromContext
StatFromContext extracts the current stat client.
Functions ¶
func NewRouter ¶
func NewRouter(conf *RouterConfig) *chi.Mux
NewRouter generates a mux that already has AWS Lambda API routes bound. This version returns a mux from the chi project as a convenience for cases where custom middleware or additional routes need to be configured.
func Start ¶
Start is maintained for backwards compatibility but is deprecated. The original intent was a single entry point that would switch behaviors based on a build flag. However, build flags are not persisted after the build so the build-time selection is not actually available for switching at runtime. As a result, this function now only starts the HTTP server.
func StartHTTPMock ¶
StartHTTPMock runs the HTTP API with mocked out functions.
func StartLambda ¶
StartLambda runs the target function from the fetcher as a native lambda server.
Types ¶
type Fetcher ¶
type Fetcher interface { // Fetch uses some implementation of a loading strategy // to fetch the Handler with the given name. If a matching Handler // cannot be found then this component must emit a NotFoundError. Fetch(ctx context.Context, name string) (Function, error) }
Fetcher is a pluggable component that enables different loading strategies functions.
type Function ¶
Function is an executable lambda function. This extends the official lambda SDK concept of a Handler in order to also provide the underlying function signature which is usually masked when converting any function to a lambda.Handler.
func NewFunction ¶
func NewFunction(v interface{}) Function
NewFunction is a replacement for lambda.NewHandler that returns a Function.
func NewFunctionWithErrors ¶ added in v0.2.0
NewFunctionWithErrors allows for documenting the various error types that can be returned by the function. This may be used when running in mock + http build modes to trigger exceptions.
type Invoke ¶
type Invoke struct { LogFn LogFn StatFn StatFn URLParamFn URLParamFn Fetcher Fetcher MockMode bool }
Invoke implements the API of the same name from the AWS Lambda API. https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
While the intent is to make this endpoint as similar to the Invoke API as possible, there are several features that are not yet supported:
- The "Tail" option for the LogType header does not cause the response to include partial logs.
- The "Qualifier" parameter is currently ignored and the reported execution version is always "latest".
- The "Function-Error" header is always "Unhandled" in the event of an exception.
This implementation also provides one extra feature which is that sending an X-Amz-Invocation-Type header with the value "Error" and an X-Error-Type header with the value of the corresponding "errType" value of a Lambda error response will trigger that err while in mock mode. Not that this is only enabled while running in mock mode and will only work if the given error type is actually in the set of known error values returned by the function. The only known error types are the ones provided when constructing the function using NewFunctionWithErrors. A 404 is issued if the requested error is not available.
type LambdaFunction ¶
LambdaFunction is a small wrapper around the lambda.Handler that preserves the original signature of the function for later retrieval.
func (*LambdaFunction) Errors ¶ added in v0.2.0
func (f *LambdaFunction) Errors() []error
Errors returns a list of errors the Lambda might return. This is only populated if the function was constructed using the NewFunctionWithErrors constructor.
func (*LambdaFunction) Source ¶
func (f *LambdaFunction) Source() interface{}
Source returns the original function signature.
type Logger ¶
Logger is an alias for the chosen project logging library which is, currently, logevent. All references in the project should be to this name rather than logevent directly.
type MockingFetcher ¶
type MockingFetcher struct {
Fetcher Fetcher
}
MockingFetcher sources original functions from another Fetcher and mocks out the results.
type NotFoundError ¶
type NotFoundError struct { // ID is the key used when looking for the resource. ID string }
NotFoundError represents a failed lookup for a resource.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type RouterConfig ¶
type RouterConfig struct { // HealthCheck defines the route on which the service will respond // with automatic 200s. This is here to integrate with systems that // poll for liveliness. The default value is /healthcheck HealthCheck string // Fetcher is the Lambda function loader that will // be used by the runtime. There is no default for this value. Fetcher Fetcher // LogFn is used to extract the request logger from the request // context. The default value is logevent.FromContext. LogFn LogFn // StatFn is used to extract the request stat client from the // request context. The default value is xstats.FromContext. StatFn StatFn // URLParamFn is used to extract URL parameters from the request. // The default value is chi.URLParam to match the usage of chi // as a mux in the default case. URLParamFn URLParamFn // MockMode should be set to enable mock mode features like error simulation. MockMode bool }
RouterConfig is used to alter the behavior of the default router and the HTTP endpoint handlers that it manages.
type Stat ¶
Stat is an alias for the chosen project metrics library which is, currently, xstats. All references in the project should be to this name rather than xstats directly.
type StaticFetcher ¶
type StaticFetcher struct { // Functions is the underlying static map of function names to executable // functions. The keys of the map will be used as the name of the Function. Functions map[string]Function }
StaticFetcher is an implementation of the Fetcher that maintains a static mapping of names to Function instances. This implementation is a highly simplified form for the purposes of reducing risk in operations. Notably, runtimes that leverage this implementation do not need to perform any orchestration of external systems as all invocations of the Functions happen within the process and share the runtime's resources. Additionally, there is no "live update" feature which means there are less moving parts that might fail when attempting to start or update a Function.
The trade-off is that updates to, additions of, and removals of Functions must be accomplished by generating a new build and redeploying the runtime. There are no options for updating or adding in-place. Operators and developers who choose this feature must take care that redeployments of the system do not cause downtime as all Functions will be affected together.
type URLParamFn ¶
URLParamFn should be accepted by HTTP handlers that need to interface with the mux in use in order to extract request parameters from the URL. This defines the contract between any given mux and a handler so that the two do not need to be coupled.