golambda

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 8 Imported by: 0

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartHandlerFunc

func StartHandlerFunc[TIn any, TOut any, H lambda.HandlerFunc[TIn, TOut]](handler H, options ...start.Option)

StartHandlerFunc calls lambda.StartHandlerFunc passing the given handler after wrapping the context with a metrics instance that is used to populate basis statistics about the invocation.

Use this wrapper if there isn't one created for specific events.

Types

This section is empty.

Directories

Path Synopsis
ddb
Package yagl provides Yet-Another-Go-Logger interface, because there isn't enough of them in Go ecosystem already.
Package yagl provides Yet-Another-Go-Logger interface, because there isn't enough of them in Go ecosystem already.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL