Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Path this config block maps to Path string // AWS Access Key. If omitted, AWS_ACCESS_KEY_ID env var is used. AwsAccess string // AWS Secret Key. If omitted, AWS_SECRET_ACCESS_KEY env var is used. AwsSecret string // AWS Region. If omitted, AWS_REGION env var is used. AwsRegion string // Optional qualifier to use on Invoke requests. // This can be used to pin a configuration to a particular alias (e.g. 'prod' or 'dev') Qualifier string // Function name include rules. Prefix and suffix '*' globs are supported. // Functions matching *any* of these rules will be proxied. // If Include is empty, all function names will be allowed (unless explicitly excluded). Include []string // Function name exclude rules. Prefix and suffix '*" globs are supported. // Functions matching *any* of these rules will be excluded, and not proxied. // If Exclude is empty, no exclude rules will be applied. Exclude []string // Optional strings to prepend or append to the parsed function name from the URL // before invoking the lambda. These are applied after the Include/Exclude rules are run NamePrepend string NameAppend string // If set, all requests to this path will invoke this function. // The function name will not be parsed from the URL. // This is useful for cases where you are multiplexing requests inside // the lambda function itself. // // Note: If set, Include and Exclude will be ignored. // Single string // If true, the Path field and function name will be removed from the // RequestMeta.Path sent to the lambda function. If Single is set, // only the Path will be removed. // // For example, given: awslambda /api/ and a request to: /api/hello/foo // the RequestMeta.Path would be /foo StripPathPrefix bool // headers to set in the upstream "headers" array - caddy placeholders work here UpstreamHeaders map[string][]string // contains filtered or unexported fields }
Config specifies configuration for a single awslambda block
func ParseConfigs ¶
func ParseConfigs(c *caddy.Controller) ([]*Config, error)
ParseConfigs parses a Caddy awslambda config block into a Config struct.
func (*Config) AcceptsFunction ¶
AcceptsFunction tests whether the given function name is supported for this configuration by applying the Include and Exclude rules.
Some additional lightweight sanity tests are also performed. For example, empty strings and names containing periods (prohibited by AWS Lambda) will return false, but there is no attempt to ensure that all AWS Lambda naming rules are validated. That is, some invalid names could be passed through.
func (*Config) MaybeToInvokeInput ¶
MaybeToInvokeInput returns a new InvokeInput instanced based on the HTTP request. If the function name parsed from the r.URL.Path doesn't comply with the Config's include/exclude rules, then nil, nil is returned. Otherwise an InvokeInput is returned with all fields populated based on the http.Request, and the NameAppend and NamePrepend rules applied (if any).
func (*Config) ParseFunction ¶
ParseFunction returns the fragment of path immediately after the config path, excluding string and named anchors.
For example, given a path of '/lambda/my-func/pathparam?a=/foo', ParseFunction returns 'my-func'
func (*Config) ToAwsConfig ¶
ToAwsConfig returns a new *aws.Config instance using the AWS related values on Config. If AwsRegion is empty, the AWS_REGION env var is used. If AwsAccess is empty, the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars are used.
type Handler ¶
type Handler struct { Next httpserver.Handler Configs []*Config }
Handler represents a middleware instance that can gateway requests to AWS Lambda
func (Handler) ServeHTTP ¶
ServeHTTP satisfies the httpserver.Handler interface by proxying the request to AWS Lambda via the Invoke function
See: http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
type Invoker ¶
type Invoker interface {
Invoke(input *lambda.InvokeInput) (*lambda.InvokeOutput, error)
}
Invoker calls a single AWS Lambda function - can be mocked for tests
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.
func ParseReply ¶
ParseReply unpacks the Lambda response data into a Reply. If the reply is a JSON object with a 'type' field equal to 'HTTPJSON-REP', then data will be unmarshaled directly as a Reply struct.
If data is not a JSON object, or the object's type field is omitted or set to a string other than 'HTTPJSON-REP', then data will be set as the Reply.body and Reply.meta will contain a default struct with a 200 status and a content-type header of 'application/json'.
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