Documentation ¶
Index ¶
- func EmitError(err error)
- func GetSecretValues(secretArn string, values interface{}) error
- func GetSecretValuesWithFactory(secretArn string, values interface{}, factory SecretsManagerFactory) error
- func NewSecretsManagerMock() (*SecretsManagerMock, SecretsManagerFactory)
- func Start(callback Callback)
- type Callback
- type Error
- type Event
- func (x *Event) Bind(v interface{}) error
- func (x *Event) DecapSNSMessage() ([]EventRecord, error)
- func (x *Event) DecapSNSonSQSMessage() ([]EventRecord, error)
- func (x *Event) DecapSQSBody() ([]EventRecord, error)
- func (x *Event) EncapSNS(v interface{}) error
- func (x *Event) EncapSNSonSQSMessage(v interface{}) error
- func (x *Event) EncapSQS(v interface{}) error
- type EventRecord
- type LambdaLogger
- func (x *LambdaLogger) Debug(msg string)
- func (x *LambdaLogger) Entry() *LogEntry
- func (x *LambdaLogger) Error(msg string)
- func (x *LambdaLogger) Info(msg string)
- func (x *LambdaLogger) Set(key string, value interface{})
- func (x *LambdaLogger) Trace(msg string)
- func (x *LambdaLogger) Warn(msg string)
- func (x *LambdaLogger) With(key string, value interface{}) *LogEntry
- type LogEntry
- type SecretsManagerClient
- type SecretsManagerFactory
- type SecretsManagerMock
- type Stack
- type StackTrace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSecretValues ¶
GetSecretValues bind secret data of AWS Secrets Manager to values. values should be set as pointer of struct with json meta tag.
type mySecret struct { Token string `json:"token"` } var secret mySecret if err := golambda.GetSecretValues(secretARN, &secret); err != nil { log.Fatal("Failed: ", err) }
func GetSecretValuesWithFactory ¶ added in v1.1.0
func GetSecretValuesWithFactory(secretArn string, values interface{}, factory SecretsManagerFactory) error
GetSecretValuesWithFactory can call SecretsManager.GetSecretValue with your SecretsManagerClient by factory. It uses newDefaultSecretsManager if factory is nil
func NewSecretsManagerMock ¶ added in v1.1.2
func NewSecretsManagerMock() (*SecretsManagerMock, SecretsManagerFactory)
NewSecretsManagerMock returns both of mock and factory method of the mock for testing. Developper can set secrets value as JSON to SecretsManagerMock.Secrets with key (secretes ARN). Also the mock stores Region that is extracted from secretArn and Input of secretsmanager.GetSecretValue when invoking GetSecretValuesWithFactory.
Types ¶
type Callback ¶
Callback is callback function type of golambda.Start().
Trigger event data (SQS, SNS, etc) is included in Event.
Callback has 2 returned value. 1st value (interface{}) will be passed to Lambda. The 1st value is allowed nil if you do not want to return any value to Lambda. 2nd value (error) also will be passed to Lambda, however golambda.Start() does error handling: 1) Extract stack trace of error if err is golambda.Error 2) Send error record to sentry.io if SENTRY_DSN is set as environment variable 3) Output error log
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is error interface for deepalert to handle related variables
func (*Error) Format ¶
Format returns: - %v, %s, %q: formated message - %+v: formated message with stack trace
func (*Error) StackTrace ¶
func (x *Error) StackTrace() StackTrace
StackTrace returns stack trace that is compatible with pkg/errors
type Event ¶
Event provides lambda original event converting utilities
func (*Event) DecapSNSMessage ¶
func (x *Event) DecapSNSMessage() ([]EventRecord, error)
DecapSNSMessage decapsulate wrapped body data in SNSEvent
func (*Event) DecapSNSonSQSMessage ¶
func (x *Event) DecapSNSonSQSMessage() ([]EventRecord, error)
DecapSNSonSQSMessage decapsulate wrapped body data to in SNSEntity over SQSEvent
func (*Event) DecapSQSBody ¶
func (x *Event) DecapSQSBody() ([]EventRecord, error)
DecapSQSBody decapsulate wrapped body data in SQSEvent
func (*Event) EncapSNS ¶
EncapSNS sets v as SNS entity. This function overwrite Origin for testing. EncapSNS allows both of one record and multiple record as slice or array e.g.) ev.EncapSNS("red") -> one SNS entity in SNSEvent ev.EncapSNS([]string{"blue", "orange"}) -> two SNS entity in SNSEvent
func (*Event) EncapSNSonSQSMessage ¶
EncapSNSonSQSMessage sets v as SNS entity over SQS. This function overwrite Origin and should be used for testing. EncapSNSonSQSMessage allows both of one record and multiple record as slice or array
e.g.)
ev.EncapSNSonSQSMessage("red") // -> one SQS message on one SQS event ev.EncapSNSonSQSMessage([]string{"blue", "orange"}) // -> two SQS message on one SQS event
func (*Event) EncapSQS ¶
EncapSQS sets v as SQSEvent body. This function overwrite Origin for testing. EncapSQS allows both of one record and multiple record as slice or array e.g.)
ev.EncapSQS("red") -> one SQSMessage in SQSEvent ev.EncapSQS([]string{"blue", "orange"}) -> two SQSMessage in SQSEvent
type EventRecord ¶
type EventRecord []byte
EventRecord is decapsulate event data (e.g. Body of SQS event)
func (EventRecord) Bind ¶
func (x EventRecord) Bind(ev interface{}) error
Bind unmarshal event record to object
type LambdaLogger ¶
type LambdaLogger struct {
// contains filtered or unexported fields
}
LambdaLogger provides basic logging features for Lambda function. golambda.Logger is configured by default as global variable of golambda.
var Logger *LambdaLogger
Logger is common logging interface
func NewLambdaLogger ¶
func NewLambdaLogger(logLevel string) *LambdaLogger
NewLambdaLogger returns a new LambdaLogger. NOTE: golambda.Logger is recommended for general usage.
func (*LambdaLogger) Debug ¶
func (x *LambdaLogger) Debug(msg string)
Debug output log as Debug level message
func (*LambdaLogger) Error ¶
func (x *LambdaLogger) Error(msg string)
Error output log as Error level message
func (*LambdaLogger) Info ¶
func (x *LambdaLogger) Info(msg string)
Info output log as Info level message
func (*LambdaLogger) Set ¶
func (x *LambdaLogger) Set(key string, value interface{})
Set saves key and value to logger. The key and value are output permanently
func (*LambdaLogger) Trace ¶
func (x *LambdaLogger) Trace(msg string)
Trace output log as Trace level message
func (*LambdaLogger) Warn ¶ added in v1.1.2
func (x *LambdaLogger) Warn(msg string)
Warn output log as Warning level message
func (*LambdaLogger) With ¶
func (x *LambdaLogger) With(key string, value interface{}) *LogEntry
With adds key and value to log message. Value will be represented by zerolog.Interface
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry is one record of logging. Trace, Debug, Info and Error methods emit message and values
type SecretsManagerClient ¶ added in v1.1.0
type SecretsManagerClient interface {
GetSecretValue(*secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error)
}
SecretsManagerClient is wrapper of secretsmanager.SecretsManager
type SecretsManagerFactory ¶ added in v1.1.0
type SecretsManagerFactory func(region string) (SecretsManagerClient, error)
SecretsManagerFactory is factory function type to replace SecretsManagerClient
type SecretsManagerMock ¶ added in v1.1.2
type SecretsManagerMock struct { Secrets map[string]string Region string Input []*secretsmanager.GetSecretValueInput }
SecretsManagerMock is mock of SecretsManagerClient for testing.
func (*SecretsManagerMock) GetSecretValue ¶ added in v1.1.2
func (x *SecretsManagerMock) GetSecretValue(input *secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error)
GetSecretValue is mock method for SecretsManagerMock. It checks if the secretId (ARN) exists in SecretsManagerMock.Secrets as key. It returns a string value if extsting or ResourceNotFoundException error if not existing.
type StackTrace ¶
type StackTrace []frame
StackTrace is array of frame. It's exported for compatibility with github.com/pkg/errors
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.