Documentation
¶
Overview ¶
Package lambdahttp provides functionality to run standard Go HTTP handlers in AWS Lambda with automatic integration for various AWS services like API Gateway, ALB, and EventBridge.
Index ¶
- func GetOriginalRequest(httpRequest *http.Request) map[string]interface{}
- func NewAWSLambdaHTTPHandler(h http.Handler) func(context.Context, LambdaRequest) (Response, error)
- func StartLambdaHandler(h http.Handler)
- type APIGatewayResponse
- type IntegrationType
- type LambdaRequest
- type LambdaRequestContextKey
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOriginalRequest ¶
GetOriginalRequest retrieves the original Lambda request from the HTTP request context. Returns nil if no original request is found in the context.
func NewAWSLambdaHTTPHandler ¶
NewAWSLambdaHTTPHandler creates a new AWS Lambda handler that can be used to handle HTTP requests It takes an http.Handler and returns a function that can be used as a Lambda handler The handler will automatically detect the api gateway version and build the request accordingly It also handles the case where the request is coming from an ALB
Supported integration types: - APIGWv1: API Gateway v1 - APIGWv2: API Gateway v2 (also used by eventBridge and lambda function url) - ALB: Application Load Balancer
func StartLambdaHandler ¶
StartLambdaHandler starts the lambda handler It takes an http.Handler and runs it within a lambda The handler will automatically detect the api gateway version and build the request accordingly It also handles the case where the request is coming from an ALB
Supported integration types: - APIGWv1: API Gateway v1 - APIGWv2: API Gateway v2 (also used by eventBridge and lambda function url) - ALB: Application Load Balancer
Types ¶
type APIGatewayResponse ¶
type APIGatewayResponse struct {
events.APIGatewayProxyResponse
}
APIGatewayResponse represents the response format required by AWS API Gateway. It contains the status code, headers, and body of the HTTP response.
func (APIGatewayResponse) GetBody ¶
func (r APIGatewayResponse) GetBody() string
GetBody returns the response body as a string. If the body is base64 encoded, it will be decoded before returning.
func (APIGatewayResponse) GetHeaders ¶
func (r APIGatewayResponse) GetHeaders() http.Header
GetHeaders returns the HTTP headers of the response
func (APIGatewayResponse) GetStatusCode ¶
func (r APIGatewayResponse) GetStatusCode() int
GetStatusCode returns the HTTP status code of the response
type IntegrationType ¶
type IntegrationType int
IntegrationType represents the type of AWS integration
const ( // IntegrationTypeUnknown represents an unknown or unsupported integration type IntegrationTypeUnknown IntegrationType = iota // IntegrationTypeAPIGWv1 represents API Gateway v1 integration IntegrationTypeAPIGWv1 // IntegrationTypeAPIGWv2 represents API Gateway v2 integration IntegrationTypeAPIGWv2 // IntegrationTypeALB represents Application Load Balancer integration IntegrationTypeALB )
Integration types supported by the package
func GetIntegrationType ¶
func GetIntegrationType(httpRequest *http.Request) IntegrationType
GetIntegrationType determines the AWS integration type from the HTTP request context. Returns IntegrationTypeUnknown if the integration type cannot be determined.
func (IntegrationType) String ¶
func (i IntegrationType) String() string
type LambdaRequest ¶
type LambdaRequest struct {
Type IntegrationType
ALB *events.ALBTargetGroupRequest
APIGWv1 *events.APIGatewayProxyRequest
APIGWv2 *events.APIGatewayV2HTTPRequest
}
LambdaRequest is the request object for the lambda handler It is used to detect the integration type and build the request accordingly
func (*LambdaRequest) UnmarshalJSON ¶
func (r *LambdaRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the LambdaRequest from a JSON object
type LambdaRequestContextKey ¶
type LambdaRequestContextKey string
LambdaRequestContextKey is used to store and retrieve Lambda-specific request context values
const ( // LambdaRequestContextKeyOriginalRequest is the context key for storing the original Lambda request LambdaRequestContextKeyOriginalRequest LambdaRequestContextKey = "originalRequest" // LambdaRequestContextKeyIntegrationType is the context key for storing the integration type LambdaRequestContextKeyIntegrationType LambdaRequestContextKey = "integrationType" )
Directories
¶
| Path | Synopsis |
|---|---|
|
lambdas
|
|
|
rest-api
command
Package main demonstrates how to use the lambdahttp package to create a REST API using standard Go HTTP handlers in AWS Lambda.
|
Package main demonstrates how to use the lambdahttp package to create a REST API using standard Go HTTP handlers in AWS Lambda. |