The main features of this module are the various wrappers around different AWS Lambda events, for example:
- Lambda Function URL, supporting both BUFFERED and RESPONSE_STREAM modes.
- API Gateway HTTP Integration with custom authoriser wrapper.
- DynamoDB Stream and other events.
Other utilities:
- Must provides
Must
,Must0
,Must2
, etc. to reduce typing outif a, err := someFunction(); err != nil
. - DynamoDB needs such as modeling version attribute, timestamps, utilities around making GetItem, PutItem, UpdateItem, and DeleteItem requests.
- Metrics measures arbitrary counters, timings, properties, and produce a JSON message describing about those metrics.
- Parse or log Smithy errors.
The module is very opinionated about how things are done because they work for me, but I'm always looking for feedback and suggestions.
The root module exposes a generic wrapper that attaches a metrics instance to the context:
# Download build.py to make it easier to build and update Lambda functions.
curl --proto '=https' -fo build.py https://raw.githubusercontent.com/nguyengg/golambda/main/build.py
package main
import (
"context"
"github.com/aws/aws-lambda-go/events"
"github.com/nguyengg/golambda"
"github.com/nguyengg/golambda/logsupport"
)
func main() {
golambda.StartHandlerFunc(func(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
// will set LambdaContext.AwsRequestID to log prefix and reset upon completion.
defer logsupport.SetUpGlobalLogger(ctx)()
return events.LambdaFunctionURLResponse{
StatusCode: 200,
Body: "hello, world!",
}, nil
})
}