handler

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: MIT Imports: 8 Imported by: 3

README

cloudevents-lambda-handler

AWS Lambda handler for processing CloudEvents (from SNS/SQS/EventBridge). Create CloudEvent receiver without the need to handle the AWS Event parsing/detection.

Currently supported event sources:

  • AWS EventBridge
  • AWS SQS
  • AWS SNS

All received events are unwrapped and decoded to CloudEvent events.

For sending events checkout the CloudEvent AWS transport

Getting Started

Create your main.go file with this content:

package main

import (
	cloudevents "github.com/cloudevents/sdk-go"
	handler "github.com/jakubknejzlik/cloudevents-lambda-handler"
)

func receiver(e cloudevents.Event) error {
	// fmt.Println("Received event", e)
	return nil
}

func main() {
	h := handler.NewCloudEventsLambdaHandler(receiver)
	h.Start()
}

Build archive with AWS Lambda sources by running:

GOOS=linux go build -o main main.go && zip lambda.zip main && rm main

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudEventsLambdaHandler

type CloudEventsLambdaHandler struct {
	// contains filtered or unexported fields
}

func NewCloudEventsLambdaHandler

func NewCloudEventsLambdaHandler(receiver CloudEventsReceiver) CloudEventsLambdaHandler

func (*CloudEventsLambdaHandler) Invoke

func (h *CloudEventsLambdaHandler) Invoke(ctx context.Context, payload []byte) (res []byte, err error)

func (*CloudEventsLambdaHandler) Start

func (h *CloudEventsLambdaHandler) Start()

type CloudEventsReceiver

type CloudEventsReceiver = func(cloudevents.Event) error

type EventBridgeEvent

type EventBridgeEvent struct {
	events.CloudWatchEvent `json:",inline"`
}

func DecodeEventBridgeEvent

func DecodeEventBridgeEvent(body []byte) (message *EventBridgeEvent, ok bool)

func (*EventBridgeEvent) GetBodies

func (m *EventBridgeEvent) GetBodies() [][]byte

func (*EventBridgeEvent) IsValid

func (m *EventBridgeEvent) IsValid() bool

type SNSEvent

type SNSEvent struct {
	events.SNSEvent `json:",inline"`
}

func DecodeSNSEvent

func DecodeSNSEvent(body []byte) (message *SNSEvent, ok bool)

func (*SNSEvent) GetBodies

func (m *SNSEvent) GetBodies() [][]byte

func (*SNSEvent) IsNotification

func (m *SNSEvent) IsNotification() bool

type SQSEvent

type SQSEvent struct {
	events.SQSEvent `json:",inline"`
}

func DecodeSQSEvent

func DecodeSQSEvent(body []byte) (message *SQSEvent, ok bool)

func (*SQSEvent) GetBodies

func (m *SQSEvent) GetBodies() [][]byte

func (*SQSEvent) IsValid

func (m *SQSEvent) IsValid() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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