Categorygithub.com/nguyengg/golambda
repositorypackage
0.0.0-20240919032739-eac131825870
Repository: https://github.com/nguyengg/golambda.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Go goodies for AWS Lambda

Go Reference

The main features of this module are the various wrappers around different AWS Lambda events, for example:

Other utilities:

  • Must provides Must, Must0, Must2, etc. to reduce typing out if 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.

Getting Started

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
	})
}