lambda_loadout 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +499 -0
- data/certs/stowzilla.pem +26 -0
- data/lib/lambda_loadout/error_notifier.rb +248 -0
- data/lib/lambda_loadout/errors.rb +218 -0
- data/lib/lambda_loadout/global.rb +83 -0
- data/lib/lambda_loadout/logger.rb +256 -0
- data/lib/lambda_loadout/metrics.rb +296 -0
- data/lib/lambda_loadout/middleware.rb +137 -0
- data/lib/lambda_loadout/version.rb +5 -0
- data/lib/lambda_loadout.rb +101 -0
- data.tar.gz.sig +3 -0
- metadata +168 -0
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lambda_loadout/version'
|
|
4
|
+
require_relative 'lambda_loadout/logger'
|
|
5
|
+
require_relative 'lambda_loadout/metrics'
|
|
6
|
+
require_relative 'lambda_loadout/middleware'
|
|
7
|
+
require_relative 'lambda_loadout/errors'
|
|
8
|
+
require_relative 'lambda_loadout/error_notifier'
|
|
9
|
+
require_relative 'lambda_loadout/global'
|
|
10
|
+
|
|
11
|
+
# LambdaLoadout - AWS Lambda Powertools for Ruby
|
|
12
|
+
#
|
|
13
|
+
# A Ruby implementation of AWS Lambda Powertools providing:
|
|
14
|
+
# - Structured logging with Lambda context enrichment
|
|
15
|
+
# - CloudWatch Metrics via Embedded Metric Format (EMF)
|
|
16
|
+
# - Automatic error tracking and alerting
|
|
17
|
+
# - Lambda middleware for easy integration
|
|
18
|
+
#
|
|
19
|
+
# @example Basic usage
|
|
20
|
+
# require 'lambda_loadout'
|
|
21
|
+
#
|
|
22
|
+
# logger = LambdaLoadout::Logger.new(service: "payment")
|
|
23
|
+
# metrics = LambdaLoadout::Metrics.new(namespace: "MyApp", service: "payment")
|
|
24
|
+
#
|
|
25
|
+
# def lambda_handler(event:, context:)
|
|
26
|
+
# LambdaLoadout.with_logging_and_metrics(logger, metrics, context) do
|
|
27
|
+
# logger.info("Processing payment")
|
|
28
|
+
# metrics.add_metric(name: "PaymentProcessed", unit: "Count", value: 1)
|
|
29
|
+
#
|
|
30
|
+
# { statusCode: 200, body: "Success" }
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
module LambdaLoadout
|
|
34
|
+
class Error < StandardError; end
|
|
35
|
+
|
|
36
|
+
# Helper method to wrap Lambda handler with logging and metrics
|
|
37
|
+
#
|
|
38
|
+
# @param logger [LambdaLoadout::Logger] Logger instance
|
|
39
|
+
# @param metrics [LambdaLoadout::Metrics] Metrics instance
|
|
40
|
+
# @param context [Object] Lambda context
|
|
41
|
+
# @param event [Hash] Lambda event (optional, required for error notifications)
|
|
42
|
+
# @param capture_cold_start [Boolean] Whether to capture cold start metric
|
|
43
|
+
# @param error_notification_config [Hash, nil] Error notification configuration
|
|
44
|
+
# - :sns_topic_arn [String] SNS topic ARN for error notifications
|
|
45
|
+
# - :region [String] AWS region (optional, defaults to AWS_REGION env var)
|
|
46
|
+
# @yield Block containing Lambda handler logic
|
|
47
|
+
# @return [Object] Result of the block
|
|
48
|
+
#
|
|
49
|
+
# @example With error notifications
|
|
50
|
+
# LambdaLoadout.with_logging_and_metrics(
|
|
51
|
+
# logger, metrics, context, event: event,
|
|
52
|
+
# error_notification_config: { sns_topic_arn: ENV['ERROR_NOTIFICATION_TOPIC_ARN'] }
|
|
53
|
+
# ) do
|
|
54
|
+
# # Your Lambda code here
|
|
55
|
+
# end
|
|
56
|
+
def self.with_logging_and_metrics(logger, metrics, context, event: nil, capture_cold_start: true,
|
|
57
|
+
error_notification_config: nil, &block)
|
|
58
|
+
logger.inject_lambda_context(context)
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
result = block.call
|
|
62
|
+
metrics.add_cold_start_metric(context) if capture_cold_start
|
|
63
|
+
result
|
|
64
|
+
rescue StandardError => e
|
|
65
|
+
logger.error('Lambda execution failed', e)
|
|
66
|
+
metrics.add_metric(name: 'LambdaError', unit: 'Count', value: 1)
|
|
67
|
+
|
|
68
|
+
# Send error notification if configured
|
|
69
|
+
if error_notification_config && error_notification_config[:sns_topic_arn]
|
|
70
|
+
notifier = ErrorNotifier.new(
|
|
71
|
+
sns_topic_arn: error_notification_config[:sns_topic_arn],
|
|
72
|
+
logger: logger,
|
|
73
|
+
region: error_notification_config[:region]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
notifier.notify(error: e, context: context, event: event || {})
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
raise
|
|
80
|
+
ensure
|
|
81
|
+
metrics.flush
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Check if running in AWS Lambda environment
|
|
86
|
+
#
|
|
87
|
+
# @return [Boolean] true if running in Lambda
|
|
88
|
+
def self.in_lambda?
|
|
89
|
+
!ENV['AWS_LAMBDA_FUNCTION_NAME'].nil?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Get cold start status
|
|
93
|
+
#
|
|
94
|
+
# @return [Boolean] true if this is a cold start
|
|
95
|
+
def self.cold_start?
|
|
96
|
+
@cold_start ||= true
|
|
97
|
+
current_cold_start = @cold_start
|
|
98
|
+
@cold_start = false
|
|
99
|
+
current_cold_start
|
|
100
|
+
end
|
|
101
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lambda_loadout
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andy Davis
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain:
|
|
10
|
+
- |
|
|
11
|
+
-----BEGIN CERTIFICATE-----
|
|
12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HREEFzAVgRNhZ2VudEBzdG93emlsbGEuY29tMB4GA1UdEgQXMBWB
|
|
27
|
+
E2FnZW50QHN0b3d6aWxsYS5jb20wDQYJKoZIhvcNAQELBQADggGBACm9Fjit/UCv
|
|
28
|
+
FxlKqeiCTIG94cIx+QrWAOJSx9knKydwUec1u04D/DbfZjTn3C2Bj227QgxeUn+6
|
|
29
|
+
if3e2v7zAk1896hLmGYzML0+nxQPb0vmtdLR7HETUlSKTVabcv1fbwLyjsuGrBvk
|
|
30
|
+
y51vOEzUEZ508a9yepLYqrQu1kOju4d57c9oA5l3H0mMKWz7av9tFj0B+STvuaWk
|
|
31
|
+
HRYDWc5HgOEVTyV+w0uFt2Kw4OCb8C42uSvC5RfYYtw78MSP+5Ru+LXJ7XOtmuN0
|
|
32
|
+
E6GVmofQ17ig9O3rgfFbMendSInrRmvPIGswvM1yivq9NOllFbdck2OJKPx6FCJF
|
|
33
|
+
7SJIkXQfc9P4B5iASIV1d1FsE0YX+g3jHXPJK/4mGL5bAyBKzpMfQB/mg6vQBzkh
|
|
34
|
+
aOKPwcreFj7TznBl89R5tNS9wZQfPVR98zgPyocddWhK18eQNMSBUnv4eeJ8PPbk
|
|
35
|
+
DovL+G8ajHDZ9fjH/+GVYHEMuiVdLarXrKJpHC1VfGTTUAp4NSEpUQ==
|
|
36
|
+
-----END CERTIFICATE-----
|
|
37
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
38
|
+
dependencies:
|
|
39
|
+
- !ruby/object:Gem::Dependency
|
|
40
|
+
name: aws-sdk-sns
|
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - "~>"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.0'
|
|
46
|
+
type: :runtime
|
|
47
|
+
prerelease: false
|
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - "~>"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '1.0'
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: json
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '2.0'
|
|
60
|
+
type: :runtime
|
|
61
|
+
prerelease: false
|
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '2.0'
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
name: rake
|
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '13.0'
|
|
74
|
+
type: :development
|
|
75
|
+
prerelease: false
|
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '13.0'
|
|
81
|
+
- !ruby/object:Gem::Dependency
|
|
82
|
+
name: rspec
|
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - "~>"
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '3.12'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - "~>"
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '3.12'
|
|
95
|
+
- !ruby/object:Gem::Dependency
|
|
96
|
+
name: rubocop
|
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - "~>"
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '1.0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - "~>"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '1.0'
|
|
109
|
+
- !ruby/object:Gem::Dependency
|
|
110
|
+
name: simplecov
|
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - "~>"
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0.22'
|
|
116
|
+
type: :development
|
|
117
|
+
prerelease: false
|
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - "~>"
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0.22'
|
|
123
|
+
description: Structured logging, CloudWatch metrics (EMF), error handling, and alerting
|
|
124
|
+
for AWS Lambda functions. Implement serverless best practices with minimal overhead.
|
|
125
|
+
email:
|
|
126
|
+
- andy@stowzilla.com
|
|
127
|
+
executables: []
|
|
128
|
+
extensions: []
|
|
129
|
+
extra_rdoc_files: []
|
|
130
|
+
files:
|
|
131
|
+
- CHANGELOG.md
|
|
132
|
+
- LICENSE.txt
|
|
133
|
+
- README.md
|
|
134
|
+
- certs/stowzilla.pem
|
|
135
|
+
- lib/lambda_loadout.rb
|
|
136
|
+
- lib/lambda_loadout/error_notifier.rb
|
|
137
|
+
- lib/lambda_loadout/errors.rb
|
|
138
|
+
- lib/lambda_loadout/global.rb
|
|
139
|
+
- lib/lambda_loadout/logger.rb
|
|
140
|
+
- lib/lambda_loadout/metrics.rb
|
|
141
|
+
- lib/lambda_loadout/middleware.rb
|
|
142
|
+
- lib/lambda_loadout/version.rb
|
|
143
|
+
homepage: https://github.com/stowzilla/lambda-loadout
|
|
144
|
+
licenses:
|
|
145
|
+
- MIT
|
|
146
|
+
metadata:
|
|
147
|
+
rubygems_mfa_required: 'true'
|
|
148
|
+
homepage_uri: https://github.com/stowzilla/lambda-loadout
|
|
149
|
+
source_code_uri: https://github.com/stowzilla/lambda-loadout/tree/main
|
|
150
|
+
changelog_uri: https://github.com/stowzilla/lambda-loadout/blob/main/CHANGELOG.md
|
|
151
|
+
rdoc_options: []
|
|
152
|
+
require_paths:
|
|
153
|
+
- lib
|
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '3.2'
|
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
|
+
requirements:
|
|
161
|
+
- - ">="
|
|
162
|
+
- !ruby/object:Gem::Version
|
|
163
|
+
version: '0'
|
|
164
|
+
requirements: []
|
|
165
|
+
rubygems_version: 3.6.9
|
|
166
|
+
specification_version: 4
|
|
167
|
+
summary: AWS Lambda Powertools for Ruby - Observability toolkit for AWS Lambda
|
|
168
|
+
test_files: []
|
metadata.gz.sig
ADDED
|
Binary file
|