DynamoDB

To create a DynamoDB reactor that subscribes via an EventSourceMapping, use the NewDynamoDBReactor constructor as in:

import (
  awsLambdaEvents "github.com/aws/aws-lambda-go/events"
  spartaArchetype "github.com/mweagle/Sparta/v3/archetype"
)
// DynamoDB reactor function
func reactorFunc(ctx context.Context,
  dynamoEvent awsLambdaEvents.DynamoDBEvent) (interface{}, error) {
  logger, _ := ctx.Value(sparta.ContextKeyRequestLogger).(*zerolog.Logger)

  logger.Info().
    Interface("Event", dynamoEvent).
    Msg("DynamoDB Event")

  return "Hello World 👋. Welcome to AWS Lambda! 🙌🎉🍾", nil
}

func main() {
  // ...
  handler := spartaArchetype.DynamoDBReactorFunc(reactorFunc)
  lambdaFn, lambdaFnErr := spartaArchetype.NewDynamoDBReactor(handler,
    "DYNAMO_DB_ARN_OR_CLOUDFORMATION_REF_VALUE",
    "TRIM_HORIZON",
    10,
    nil)
}