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

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 cloudwatch.go codecommit.go doc.go dynamodb.go kinesis.go s3.go sns.go

func NewCloudWatchEventedReactor Uses

func NewCloudWatchEventedReactor(reactor CloudWatchReactor,
    eventPatterns map[string]map[string]interface{},
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewCloudWatchEventedReactor returns a CloudWatch logs reactor lambda function that executes in response to the given events. The eventPatterns map is a map of names to map[string]interface{} values that represents the events to listen to. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html for the proper syntax. Example:

map[string]interface{}{
	"source":      []string{"aws.ec2"},
	"detail-type": []string{"EC2 Instance state change"},
}

func NewCloudWatchReactor Uses

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

NewCloudWatchReactor returns a CloudWatch logs reactor lambda function

func NewCloudWatchScheduledReactor Uses

func NewCloudWatchScheduledReactor(reactor CloudWatchReactor,
    cronSchedules map[string]string,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewCloudWatchScheduledReactor returns a CloudWatch logs reactor lambda function that executes with the given schedule. The cronSchedules map is a map of names to ScheduleExpressions. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#RateExpressions for the proper syntax. Example:

"rate(5 minutes)"

func NewCodeCommitReactor Uses

func NewCodeCommitReactor(reactor CodeCommitReactor,
    repositoryName gocf.Stringable,
    branches []string,
    events []string,
    additionalLambdaPermissions []sparta.IAMRolePrivilege) (*sparta.LambdaAWSInfo, error)

NewCodeCommitReactor returns an SNS 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 CloudWatchReactor Uses

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

CloudWatchReactor represents a lambda function that responds to CW messages

type CloudWatchReactorFunc Uses

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

CloudWatchReactorFunc is a free function that adapts a CloudWatchReactor compliant signature into a function that exposes an OnEvent function

func (CloudWatchReactorFunc) OnCloudWatchMessage Uses

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

OnCloudWatchMessage satisfies the CloudWatchReactor interface

func (CloudWatchReactorFunc) ReactorName Uses

func (reactorFunc CloudWatchReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type CodeCommitReactor Uses

type CodeCommitReactor interface {
    // OnCodeCommitEvent when an SNS event occurs. Check the codeCommitEvent field
    // for the specific event
    OnCodeCommitEvent(ctx context.Context, codeCommitEvent awsLambdaEvents.CodeCommitEvent) (interface{}, error)
}

CodeCommitReactor represents a lambda function that responds to CodeCommit events

type CodeCommitReactorFunc Uses

type CodeCommitReactorFunc func(ctx context.Context,
    codeCommitEvent awsLambdaEvents.CodeCommitEvent) (interface{}, error)

CodeCommitReactorFunc is a free function that adapts a CodeCommitReactor compliant signature into a function that exposes an OnEvent function

func (CodeCommitReactorFunc) OnCodeCommitEvent Uses

func (reactorFunc CodeCommitReactorFunc) OnCodeCommitEvent(ctx context.Context,
    codeCommitEvent awsLambdaEvents.CodeCommitEvent) (interface{}, error)

OnCodeCommitEvent satisfies the CodeCommitReactor interface

func (CodeCommitReactorFunc) ReactorName Uses

func (reactorFunc CodeCommitReactorFunc) 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

Directories

PathSynopsis
restPackage rest provides a set of utility functions to make building REST-based services simpler.

Package archetype imports 11 packages (graph). Updated 2019-02-08. Refresh now. Tools for package owners.