warhead-lambda
Warhead uses adapters to provide an abstraction layer with a unified interface atop any given platform.
adapter(handler)
A Warhead adapter for AWS Lambda functions.
const adapter = exportshandler =
Arguments:
- Handler function with up to 2 arguments.
- An instance of
Request
which contains all the request information . - The context object provided by AWS Lambda which can also be access via the
this
variable.
- An instance of
For synchronous operations, you may return a value or Response.
return foo: 'bar'
For asynchronous operations, you may return a Promise
that resolves a value or a Response
.
return Promise
If the value returned by the handler is not an instance of Response
, it will be wrapped in a Response
with a default response code of 200
and a content-type
header of application/json
automatically.
If an error is thrown or a Promise is rejected with a value other than a Response
, it will be wrapped in a Response
with a default response code of 500
and a content-type
header of application/json
automatically.
Response([body])
A constructor for building a proper response for AWS Lambda's proxy integration.
Arguments:
- The desired response body.
- A transformation function used to stringify the body, defaults to
JSON.stringify
.
If an object is provided, it will automatically be stringified. New instances default to a response code of 200
and a content-type
header of application/json
.
const adapter Response = exportshandler =
response.status([code])
Set or get status code of a response.
const Response = const response = message: 'Hello World!'responsestatus200
response.header(name, [value])
Set or get a header of a response.
const Response = const response = message: 'Hello World!'response
test-helpers
Helpers for testing functions written with the warhead-lambda
adapter.
harness()
A harness for testing a lambda function.
const request = body: foo: 'bar'const handler =