Documentation
¶
Index ¶
- Variables
- func GetParameter(ctx context.Context, input *ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
- func GetSecretValue(ctx context.Context, input *secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error)
- func SetUpSlogDefault()
- func Start[TIn any, H ConsumerFunc[TIn]](handler H, options ...awslambda.Option)
- func StartDynamodbEventHandler(handler func(context.Context, events.DynamoDBEventRecord) error, ...)
- 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, ...)
- func StreamToDynamoDBAttributeValue(av events.DynamoDBAttributeValue) dynamodbtypes.AttributeValue
- func StreamToDynamoDBItem(in map[string]events.DynamoDBAttributeValue) map[string]dynamodbtypes.AttributeValue
- 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 ¶
This section is empty.
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 SetUpSlogDefault ¶ added in v0.4.0
func SetUpSlogDefault()
SetUpSlogDefault sets the default slog.Default to print JSON messages to os.Stderr, respecting AWS_LAMBDA_LOG_FORMAT and AWS_LAMBDA_LOG_LEVEL if given.
Replicates the logic of lambdacontext.NewLogHandler with a few key differences:
- "awsRequestId" is used instead of "requestId".
- defaults to JSON handler if AWS_LAMBDA_LOG_FORMAT is not given.
- if DEBUG environment variable is true-ish, override AWS_LAMBDA_LOG_LEVEL to DEBUG.
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 StartDynamodbEventHandler ¶ added in v0.4.3
func StartDynamodbEventHandler(handler func(context.Context, events.DynamoDBEventRecord) error, options ...lambda.Option)
StartDynamodbEventHandler starts the Lambda loop for handling DynamoDB stream events in a batch.
See https://docs.aws.amazon.com/lambda/latest/dg/services-ddb-batchfailurereporting.html.
The handler works on one record at a time and sequentially. If the handler returns a non-nil error, the wrapper will automatically add an events.DynamoDBBatchItemFailure so that only failed records get retried later.
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.
func StreamToDynamoDBAttributeValue ¶ added in v0.4.3
func StreamToDynamoDBAttributeValue(av events.DynamoDBAttributeValue) dynamodbtypes.AttributeValue
StreamToDynamoDBAttributeValue converts a DynamoDB Stream event attribute value (from https://pkg.go.dev/github.com/aws/aws-lambda-go/events) to an equivalent DynamoDB attribute value (from https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/dynamodb/types).
See StreamToDynamoDBItem for usage.
func StreamToDynamoDBItem ¶ added in v0.4.3
func StreamToDynamoDBItem(in map[string]events.DynamoDBAttributeValue) map[string]dynamodbtypes.AttributeValue
StreamToDynamoDBItem uses StreamToDynamoDBAttributeValue to convert an item from a DynamoDB Stream event to an item in DynamoDB.
Useful if you're implementing a DynamoDB Stream event handler, and you need to convert the old and/or new image to the tagged struct by way of https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue:
item := &MyStruct{}
err := attributevalue.UnmarshalMap(StreamToDynamoDBItem(record.Change.NewImage), item)
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)