Documentation
¶
Overview ¶
Package lambda provides utilities for handling AWS Lambda events and responses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ProxyResponseWriter ¶
type ProxyResponseWriter struct {
// contains filtered or unexported fields
}
ProxyResponseWriter implements http.ResponseWriter and adds the method necessary to return an events.ALBTargetGroupResponse object.
func NewProxyResponseWriter ¶
func NewProxyResponseWriter() *ProxyResponseWriter
NewProxyResponseWriter returns a new ProxyResponseWriter object. The object is initialized with an empty map of headers and a status code of -1.
func (*ProxyResponseWriter) CloseNotify ¶
func (r *ProxyResponseWriter) CloseNotify() <-chan bool
CloseNotify implements http.CloseNotifier for compatibility.
func (*ProxyResponseWriter) GetLambdaResponse ¶
func (r *ProxyResponseWriter) GetLambdaResponse() (Response, error)
GetLambdaResponse converts the data passed to the response writer into an Response object. Returns a populated lambda response object. If the response is invalid, for example has no headers or an invalid status code returns an error.
func (*ProxyResponseWriter) Header ¶
func (r *ProxyResponseWriter) Header() http.Header
Header implementation from the http.ResponseWriter interface.
func (*ProxyResponseWriter) Write ¶
func (r *ProxyResponseWriter) Write(body []byte) (int, error)
Write sets the response body in the object. If no status code was set before with the WriteHeader method it sets the status for the response to 200 OK.
func (*ProxyResponseWriter) WriteHeader ¶
func (r *ProxyResponseWriter) WriteHeader(status int)
WriteHeader sets a status code for the response. This method is used for error responses.
type Request ¶
type Request struct {
Version string `json:"version"`
Path string `json:"path"`
HTTPMethod string `json:"httpMethod"`
Headers map[string]string `json:"headers"`
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
RequestContext RequestContext `json:"requestContext"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
RawPath string `json:"rawPath"`
RawQueryString string `json:"rawQueryString"`
}
Request is a generic request that works with both ALB and API Gateway.
func FromALBRequest ¶
func FromALBRequest(alb awsevents.ALBTargetGroupRequest) Request
FromALBRequest converts an ALB request to a generic Request.
func FromAPIGatewayRequest ¶
func FromAPIGatewayRequest(apigw awsevents.APIGatewayV2HTTPRequest) Request
FromAPIGatewayRequest converts an API Gateway request to a generic Request.
type RequestContext ¶
type RequestContext struct {
// API Gateway fields
HTTP struct {
Method string `json:"method"`
Path string `json:"path"`
Protocol string `json:"protocol"`
SourceIP string `json:"sourceIp"`
UserAgent string `json:"userAgent"`
Headers map[string]string `json:"headers"`
} `json:"http"`
// ALB fields
ELB struct {
TargetGroupArn string `json:"targetGroupArn"`
} `json:"elb"`
}
RequestContext combines the relevant fields from ALB and API Gateway contexts.
type Response ¶
type Response struct {
StatusCode int `json:"statusCode"`
Headers map[string]string `json:"headers"`
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
Cookies []string `json:"cookies"`
}
Response mimics ALBTargetGroupResponse and APIGatewayV2HTTPResponse.