archetype

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 11 Imported by: 0

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 NewCloudWatchEventedReactor added in v1.7.3

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 added in v1.7.3

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 added in v1.7.3

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 added in v1.9.1

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

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 CloudWatchReactor added in v1.8.0

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 added in v1.8.0

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 added in v1.8.0

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

OnCloudWatchMessage satisfies the CloudWatchReactor interface

func (CloudWatchReactorFunc) ReactorName added in v1.8.0

func (reactorFunc CloudWatchReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type CodeCommitReactor added in v1.9.1

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 added in v1.9.1

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 added in v1.9.1

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

OnCodeCommitEvent satisfies the CodeCommitReactor interface

func (CodeCommitReactorFunc) ReactorName added in v1.9.1

func (reactorFunc CodeCommitReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

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

func (DynamoDBReactorFunc) ReactorName added in v1.5.0

func (reactorFunc DynamoDBReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

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

func (KinesisReactorFunc) ReactorName added in v1.5.0

func (reactorFunc KinesisReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

type ReactorNameProvider added in v1.5.0

type ReactorNameProvider interface {
	ReactorName() string
}

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

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

func (S3ReactorFunc) ReactorName added in v1.5.0

func (reactorFunc S3ReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

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

func (SNSReactorFunc) ReactorName added in v1.5.0

func (reactorFunc SNSReactorFunc) ReactorName() string

ReactorName provides the name of the reactor func

Directories

Path Synopsis
Package rest provides a set of utility functions to make building REST-based services simpler.
Package rest provides a set of utility functions to make building REST-based services simpler.

Jump to

Keyboard shortcuts

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