Sparta: github.com/mweagle/Sparta/archetype Index | Examples | Files

package archetype

import "github.com/mweagle/Sparta/archetype"

Package archetype provides a set of convenience functions that transform a free function or struct implementing a specific interface into a *sparta.LambdaAWSInfo struct complete with the necessary AWS permissions.

Index

Examples

Package Files

archetype.go cloudwatchLogs.go doc.go dynamodb.go kinesis.go s3.go sns.go

func NewCloudWatchLogsReactor Uses

func NewCloudWatchLogsReactor(reactor CloudWatchLogsReactor,
    subscriptions map[string]sparta.CloudWatchEventsRule,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewCloudWatchLogsReactor returns a CloudWatch logs reactor lambda function

func NewDynamoDBReactor Uses

func NewDynamoDBReactor(reactor DynamoDBReactor,
    dynamoDBARN gocf.Stringable,
    startingPosition string,
    batchSize int64,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewDynamoDBReactor returns an Kinesis reactor lambda function

func NewKinesisReactor Uses

func NewKinesisReactor(reactor KinesisReactor,
    kinesisStream gocf.Stringable,
    startingPosition string,
    batchSize int64,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewKinesisReactor returns an Kinesis reactor lambda function

func NewS3Reactor Uses

func NewS3Reactor(reactor S3Reactor, s3Bucket gocf.Stringable, additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewS3Reactor returns an S3 reactor lambda function

func NewS3ScopedReactor Uses

func NewS3ScopedReactor(reactor S3Reactor,
    s3Bucket gocf.Stringable,
    keyPathPrefix string,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewS3ScopedReactor returns an S3 reactor lambda function scoped to the given S3 key prefix

func NewSNSReactor Uses

func NewSNSReactor(reactor SNSReactor,
    snsTopic gocf.Stringable,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewSNSReactor returns an SNS reactor lambda function

type CloudWatchLogsReactor Uses

type CloudWatchLogsReactor interface {
    // OnLogMessage when an SNS event occurs. Check the snsEvent field
    // for the specific event
    OnLogMessage(ctx context.Context,
        cwLogs awsLambdaEvents.CloudwatchLogsEvent) (interface{}, error)
}

CloudWatchLogsReactor represents a lambda function that responds to CW log messages

type CloudWatchLogsReactorFunc Uses

type CloudWatchLogsReactorFunc func(ctx context.Context,
    cwLogs awsLambdaEvents.CloudwatchLogsEvent) (interface{}, error)

CloudWatchLogsReactorFunc is a free function that adapts a CloudWatchLogsReactor compliant signature into a function that exposes an OnEvent function

func (CloudWatchLogsReactorFunc) OnLogMessage Uses

func (reactorFunc CloudWatchLogsReactorFunc) OnLogMessage(ctx context.Context,
    cwLogs awsLambdaEvents.CloudwatchLogsEvent) (interface{}, error)

OnLogMessage satisfies the CloudWatchLogsReactor interface

func (CloudWatchLogsReactorFunc) ReactorName Uses

func (reactorFunc CloudWatchLogsReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type DynamoDBReactor Uses

type DynamoDBReactor interface {
    // OnEvent when an SNS event occurs. Check the snsEvent field
    // for the specific event
    OnDynamoEvent(ctx context.Context,
        dynamoEvent awsLambdaEvents.DynamoDBEvent) (interface{}, error)
}

DynamoDBReactor represents a lambda function that responds to Dynamo messages

type DynamoDBReactorFunc Uses

type DynamoDBReactorFunc func(ctx context.Context,
    dynamoEvent awsLambdaEvents.DynamoDBEvent) (interface{}, error)

DynamoDBReactorFunc is a free function that adapts a DynamoDBReactor compliant signature into a function that exposes an OnEvent function

func (DynamoDBReactorFunc) OnDynamoEvent Uses

func (reactorFunc DynamoDBReactorFunc) OnDynamoEvent(ctx context.Context,
    dynamoEvent awsLambdaEvents.DynamoDBEvent) (interface{}, error)

OnDynamoEvent satisfies the DynamoDBReactor interface

func (DynamoDBReactorFunc) ReactorName Uses

func (reactorFunc DynamoDBReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type KinesisReactor Uses

type KinesisReactor interface {
    // OnEvent when an SNS event occurs. Check the snsEvent field
    // for the specific event
    OnKinesisMessage(ctx context.Context,
        kinesisEvent awsLambdaEvents.KinesisEvent) (interface{}, error)
}

KinesisReactor represents a lambda function that responds to Kinesis messages

type KinesisReactorFunc Uses

type KinesisReactorFunc func(ctx context.Context,
    kinesisEvent awsLambdaEvents.KinesisEvent) (interface{}, error)

KinesisReactorFunc is a free function that adapts a KinesisReactor compliant signature into a function that exposes an OnEvent function

func (KinesisReactorFunc) OnKinesisMessage Uses

func (reactorFunc KinesisReactorFunc) OnKinesisMessage(ctx context.Context,
    kinesisEvent awsLambdaEvents.KinesisEvent) (interface{}, error)

OnKinesisMessage satisfies the KinesisReactor interface

func (KinesisReactorFunc) ReactorName Uses

func (reactorFunc KinesisReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type ReactorNameProvider Uses

type ReactorNameProvider interface {
    ReactorName() string
}

ReactorNameProvider is an interface so that a reactor function can provide a custom name which prevents collisions

type S3Reactor Uses

type S3Reactor interface {
    // OnS3Event when an S3 event occurs. Check the event.EventName field
    // for the specific event
    OnS3Event(ctx context.Context, event awsLambdaEvents.S3Event) (interface{}, error)
}

S3Reactor represents a lambda function that responds to typical S3 operations

ExampleS3Reactor illustrates how to create an S3 event subscriber

Code:

inlineReactor := func(ctx context.Context,
    s3Event awsLambdaEvents.S3Event) (interface{}, error) {
    logger, loggerOk := ctx.Value(sparta.ContextKeyLogger).(*logrus.Logger)
    if loggerOk {
        for _, eachRecord := range s3Event.Records {
            logger.WithField("EventType", eachRecord.EventName).
                WithField("Entity", eachRecord.S3).
                Info("Event info")
        }
    }
    return len(s3Event.Records), nil
}
// Create the *sparta.LambdaAWSInfo wrapper
lambdaFn, lambdaFnErr := NewS3Reactor(S3ReactorFunc(inlineReactor),
    gocf.String("MY-S3-BUCKET-TO-REACT"),
    nil)
fmt.Printf("LambdaFn: %#v, LambdaFnErr: %#v", lambdaFn, lambdaFnErr)

type S3ReactorFunc Uses

type S3ReactorFunc func(ctx context.Context, event awsLambdaEvents.S3Event) (interface{}, error)

S3ReactorFunc is a free function that adapts a S3Reactor compliant signature into a function that exposes an OnS3Event function

func (S3ReactorFunc) OnS3Event Uses

func (reactorFunc S3ReactorFunc) OnS3Event(ctx context.Context, event awsLambdaEvents.S3Event) (interface{}, error)

OnS3Event satisfies the S3Reactor interface

func (S3ReactorFunc) ReactorName Uses

func (reactorFunc S3ReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type SNSReactor Uses

type SNSReactor interface {
    // OnSNSEvent when an SNS event occurs. Check the snsEvent field
    // for the specific event
    OnSNSEvent(ctx context.Context, snsEvent awsLambdaEvents.SNSEvent) (interface{}, error)
}

SNSReactor represents a lambda function that responds to typical SNS events

ExampleSNSReactor illustrates how to create an SNS notification subscriber

Code:

inlineReactor := func(ctx context.Context, snsEvent awsLambdaEvents.SNSEvent) (interface{}, error) {
    logger, loggerOk := ctx.Value(sparta.ContextKeyLogger).(*logrus.Logger)
    if loggerOk {
        logger.WithFields(logrus.Fields{
            "Event": snsEvent,
        }).Info("Event received")
    }
    return &snsEvent, nil
}
// Create the *sparta.LambdaAWSInfo wrapper
lambdaFn, lambdaFnErr := NewSNSReactor(SNSReactorFunc(inlineReactor),
    gocf.String("MY-SNS-TOPIC"),
    nil)
fmt.Printf("LambdaFn: %#v, LambdaFnErr: %#v", lambdaFn, lambdaFnErr)

type SNSReactorFunc Uses

type SNSReactorFunc func(ctx context.Context,
    snsEvent awsLambdaEvents.SNSEvent) (interface{}, error)

SNSReactorFunc is a free function that adapts a SNSReactor compliant signature into a function that exposes an OnEvent function

func (SNSReactorFunc) OnSNSEvent Uses

func (reactorFunc SNSReactorFunc) OnSNSEvent(ctx context.Context,
    snsEvent awsLambdaEvents.SNSEvent) (interface{}, error)

OnSNSEvent satisfies the SNSReactor interface

func (SNSReactorFunc) ReactorName Uses

func (reactorFunc SNSReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

Package archetype imports 11 packages (graph). Updated 2018-11-15. Refresh now. Tools for package owners.