archetype

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCloudWatchLogsReactor

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

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

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

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

NewS3Reactor returns an S3 reactor lambda function

func NewS3ScopedReactor

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

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

NewSNSReactor returns an SNS reactor lambda function

Types

type CloudWatchLogsReactor

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

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

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

OnLogMessage satisfies the CloudWatchLogsReactor interface

type DynamoDBReactor

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

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

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

OnDynamoEvent satisfies the DynamoDBReactor interface

type KinesisReactor

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

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

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

OnKinesisMessage satisfies the KinesisReactor interface

type S3Reactor

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

Example

ExampleS3Reactor illustrates how to create an S3 event subscriber

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)
Output:

type S3ReactorFunc

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

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

OnS3Event satisfies the S3Reactor interface

type SNSReactor

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

Example

ExampleSNSReactor illustrates how to create an SNS notification subscriber

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)
Output:

type SNSReactorFunc

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

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

OnSNSEvent satisfies the SNSReactor interface

Jump to

Keyboard shortcuts

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