Documentation
¶
Index ¶
- Constants
- Variables
- func GetParameter(ctx context.Context, input *ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
- func GetSecretValue(ctx context.Context, input *secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error)
- func SetUpLogDefault()
- func SetUpSlogDefault()
- func Start[TIn any, H ConsumerFunc[TIn]](handler H, options ...awslambda.Option)
- func StartHandlerFunc[TIn any, TOut any, H awslambda.HandlerFunc[TIn, TOut]](handler H, options ...awslambda.Option)
- func StartSQSMessageHandler(handler func(context.Context, events.SQSMessage) error, ...)
- type ConsumerFunc
- type ConsumerFuncOptions
- type GetParameterClient
- type GetSecretValueClient
- type HandlerFuncOptions
- type ParameterSecretsExtensionClient
- func (l *ParameterSecretsExtensionClient) GetParameter(ctx context.Context, input *ssm.GetParameterInput, _ ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
- func (l *ParameterSecretsExtensionClient) GetSecretValue(ctx context.Context, input *secretsmanager.GetSecretValueInput, ...) (*secretsmanager.GetSecretValueOutput, error)
Constants ¶
const ( // DebugLogFlags is the flag passed to log.SetFlags if DEBUG environment variable is true-ish. DebugLogFlags = log.LstdFlags | log.Lmicroseconds | log.LUTC | log.Llongfile | log.Lmsgprefix // DefaultLogFlags is the flag passed to log.SetFlags if DEBUG environment is not true-ish. DefaultLogFlags = log.LstdFlags | log.LUTC | log.Lmsgprefix )
Variables ¶
var DefaultParameterSecretsExtensionClient = &ParameterSecretsExtensionClient{Client: http.DefaultClient}
DefaultParameterSecretsExtensionClient is the client used by package-level GetSecretValue and GetParameter.
Functions ¶
func GetParameter ¶
func GetParameter(ctx context.Context, input *ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
GetParameter is a wrapper around [DefaultClient.GetParameter].
func GetSecretValue ¶
func GetSecretValue(ctx context.Context, input *secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error)
GetSecretValue is a wrapper around [DefaultClient.GetSecretValue].
func SetUpLogDefault ¶ added in v0.4.0
func SetUpLogDefault()
SetUpLogDefault sets up flags for the default logger depending on the DEBUG environment variable.
If the DEBUG environment variable is true-ish, DebugLogFlags is passed to log.SetFlags. Otherwise, DefaultLogFlags is passed to log.SetFlags.
func SetUpSlogDefault ¶ added in v0.4.0
func SetUpSlogDefault()
SetUpSlogDefault sets the default slog.Default to print JSON contents to os.Stderr.
Additionally, if DEBUG environment variable is true-ish, slog.SetLogLoggerLevel is set to slog.LevelDebug prior to the slog.SetDefault call, and the slog.JSONHandler will output messages at slog.LevelDebug level. This also has the effect of making every subsequent log.Printf to also print at slog.LevelDebug. See slog.SetLogLoggerLevel for a more in-depth explanation.
func Start ¶ added in v0.1.1
func Start[TIn any, H ConsumerFunc[TIn]](handler H, options ...awslambda.Option)
Start is a variant of StartHandlerFunc for handlers that don't have any explicit returned value.
See StartHandlerFunc for details.
func StartHandlerFunc ¶ added in v0.1.1
func StartHandlerFunc[TIn any, TOut any, H awslambda.HandlerFunc[TIn, TOut]](handler H, options ...awslambda.Option)
StartHandlerFunc is a wrapper around lambda.StartHandlerFunc that adds sensible logging and metrics out of the box.
A metrics.Metrics instance will be made available via context by way of metrics.Get. The "fault" and "panicked" counters will be populated accordingly: if the handler returns a non-nil error, "fault" will be set to 1, and "error" property to the error; if the handler panics, "panicked" will be set to 1, "error" to the recovered error, and "stack" to the stack trace.
See SetUpLogDefault and SetUpSlogDefault for how the default loggers are configured. Additionally, for each Lambda invocation, the AWS request Id will also be attached to log.Default as the message prefix, slog.Default as the attribute "awsRequestId". To disable this feature, specify either HandlerFuncOptions.NoSetUpLogging or ConsumerFuncOptions.NoSetUpLogging.
If you need to customise the metrics.Metrics instance, use NewHandlerFunc.
func StartSQSMessageHandler ¶ added in v0.2.1
func StartSQSMessageHandler(handler func(context.Context, events.SQSMessage) error, options ...lambda.Option)
StartSQSMessageHandler starts the Lambda loop for handling SQS messages in a batch.
See https://docs.aws.amazon.com/prescriptive-guidance/latest/lambda-event-filtering-partial-batch-responses-for-sqs/benefits-partial-batch-responses.html for why partial batch response is preferable over failing the entire batch.
The handler works on one message at a time and sequentially. If the handler returns a non-nil error, the wrapper will automatically add an events.SQSBatchItemFailure so that only failed messages get retried later.
Types ¶
type ConsumerFunc ¶ added in v0.3.0
ConsumerFunc is a variant of lambda.HandlerFunc that has no output (except for error).
type ConsumerFuncOptions ¶ added in v0.3.0
type ConsumerFuncOptions[TIn any, H ConsumerFunc[TIn]] struct { // NoSetUpLogging will disable logging features. NoSetUpLogging bool // contains filtered or unexported fields }
ConsumerFuncOptions is returned by NewConsumerFunc to allow further customisation.
func NewConsumerFunc ¶ added in v0.3.0
func NewConsumerFunc[TIn any, H ConsumerFunc[TIn]](handler H, options ...lambda.Option) *ConsumerFuncOptions[TIn, H]
NewConsumerFunc is a more customisable variant of Start.
You must eventually call ConsumerFuncOptions.Start to enter the Lambda loop.
func (*ConsumerFuncOptions[TIn, H]) Start ¶ added in v0.3.0
func (h *ConsumerFuncOptions[TIn, H]) Start()
Start is a variant of StartHandlerFunc for handlers that don't have any explicit returned value.
See package-level StartHandlerFunc for details.
func (*ConsumerFuncOptions[TIn, H]) WithMetricsOptions ¶ added in v0.3.0
func (h *ConsumerFuncOptions[TIn, H]) WithMetricsOptions(optFns ...func(m *metrics.Metrics)) *ConsumerFuncOptions[TIn, H]
WithMetricsOptions replaces the customisations for metrics.New.
type GetParameterClient ¶
type GetParameterClient interface {
GetParameter(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
}
GetParameterClient abstracts the GetParameter API that has an implementation using AWS Parameter and Secrets Lambda extension (ParameterSecretsExtensionClient).
type GetSecretValueClient ¶
type GetSecretValueClient interface {
GetSecretValue(ctx context.Context, params *secretsmanager.GetSecretValueInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.GetSecretValueOutput, error)
}
GetSecretValueClient abstracts the GetSecretValue API that has an implementation using AWS Parameter and Secrets Lambda extension (ParameterSecretsExtensionClient).
type HandlerFuncOptions ¶ added in v0.3.0
type HandlerFuncOptions[TIn any, TOut any, H lambda.HandlerFunc[TIn, TOut]] struct { // NoSetUpLogging will disable logging features. NoSetUpLogging bool // contains filtered or unexported fields }
HandlerFuncOptions is returned by NewHandlerFunc to allow further customisation.
func NewHandlerFunc ¶ added in v0.3.0
func NewHandlerFunc[TIn any, TOut any, H lambda.HandlerFunc[TIn, TOut]](handler H, options ...lambda.Option) *HandlerFuncOptions[TIn, TOut, H]
NewHandlerFunc is a more customisable variant of StartHandlerFunc.
You must eventually call HandlerFuncOptions.Start to enter the Lambda loop.
func (*HandlerFuncOptions[TIn, TOut, H]) Start ¶ added in v0.3.0
func (h *HandlerFuncOptions[TIn, TOut, H]) Start()
Start is a wrapper around lambda.StartHandlerFunc that adds sensible logging and metrics out of the box.
See package-level Start for details.
func (*HandlerFuncOptions[TIn, TOut, H]) WithMetricsOptions ¶ added in v0.3.0
func (h *HandlerFuncOptions[TIn, TOut, H]) WithMetricsOptions(optFns ...func(m *metrics.Metrics)) *HandlerFuncOptions[TIn, TOut, H]
WithMetricsOptions replaces the customisations for metrics.New.
type ParameterSecretsExtensionClient ¶
type ParameterSecretsExtensionClient struct {
// Client is the HTTP client to use for making HTTP requests.
//
// If nil, http.DefaultClient is used.
Client *http.Client
// contains filtered or unexported fields
}
ParameterSecretsExtensionClient implements both GetParameterClient and GetSecretValueClient using the AWS Parameter and Secrets Lambda extension.
See https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_lambda.html and https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html.
The zero-value DefaultParameterSecretsExtensionClient is ready for use.
func (*ParameterSecretsExtensionClient) GetParameter ¶
func (l *ParameterSecretsExtensionClient) GetParameter(ctx context.Context, input *ssm.GetParameterInput, _ ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
func (*ParameterSecretsExtensionClient) GetSecretValue ¶
func (l *ParameterSecretsExtensionClient) GetSecretValue(ctx context.Context, input *secretsmanager.GetSecretValueInput, _ ...func(*secretsmanager.Options)) (*secretsmanager.GetSecretValueOutput, error)