lambda_loadout 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 250f19d3ff12ebc1760156eecf60052dcf951f9ef8e2eaa52bf6b7347166299a
4
- data.tar.gz: e1209cd11b25691b1fb350b9abe9ba3b14c7268fe3a82ae365b987f55b1d7f4e
3
+ metadata.gz: 9eb2fc830c68b4e24d33e22c674efeeadcd9fb99d6098bf85a5e05b76a0f1993
4
+ data.tar.gz: e9967acf7e49ea6b9addd212d8cee2f67c3f66bd3f273310f1cde191205a81e5
5
5
  SHA512:
6
- metadata.gz: d8ccbb28817f4c606bd69fb34e83e9afb19c03b4a1b8f0d04d0479596c297f0080c8d917db2405a76f307c2a075ddf496d6007d14a33183f445f994fad0293be
7
- data.tar.gz: 2cedf03cb547d5d1ebb41d5032e3ed4598fa18f75534ea646778c4b8ab490d9d0779b891b2f0e046747461488c1a93b22c9f2d66a647a71ae26d81ec1b84c380
6
+ metadata.gz: d33bc3a26d7e4029338997d89ca3d2940bb28b3351a95925223c053f34ba55902ffb30f7a6dfec4051f5e6c8bce57c3deab6bb0364fe49d8cbfe85eeef137510
7
+ data.tar.gz: 41de982dbc56ed8aa6f12528b2d18b70e7dc04ab4cc8f9167896eb09ed3aa26d762fe139c530942574e8679bb174de5aa5fb5c88b310e2fc41f9c3dc83675b0d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.0.4] - 2026-10-30
11
+
12
+ ### Added
13
+ - The Lambda layer supports `ruby4.0` as well as `ruby3.4`. The zip carries a gem directory
14
+ for each runtime (`ruby/gems/3.4.0`, `ruby/gems/4.0.0`) and is published with both
15
+ compatible runtimes, so one layer version serves both.
16
+
17
+ ### Changed
18
+ - The `json` dependency allows json 3.x (`>= 2, < 4`). Lambda Loadout only calls
19
+ `JSON.generate` and `JSON.pretty_generate`, which behave the same in json 3.
20
+
21
+ ### Fixed
22
+ - `rake layer:build` installs the gem inside `public.ecr.aws/sam/build-ruby<version>`
23
+ rather than with the host's Ruby. Before, native extensions (`json`, `bigdecimal`) were
24
+ compiled for whatever machine ran the build, which might not load on Lambda.
25
+ Building the layer now requires Docker.
26
+ - The layer is published with `--compatible-architectures x86_64`, matching how the
27
+ extensions are built.
28
+ - `cold_start` in log lines was `true` on every invocation: `cold_start?` did
29
+ `@cold_start ||= true`, which turned `false` back into `true`. Cold start is now keyed
30
+ to the first invocation's request id, so every log line in that invocation says `true`
31
+ and later invocations say `false`. The `ColdStart` metric fires on the cold invocation
32
+ even when the handler logged first (previously the first log line used up the flag).
33
+ `LambdaLoadout.cold_start?` takes an optional context; `LambdaLoadout.reset_cold_start!`
34
+ clears the state for tests.
35
+
36
+
10
37
  ## [0.0.3] - 2026-10-23
11
38
 
12
39
  ### Added
@@ -61,5 +88,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
88
  - GitHub Actions CI (test matrix Ruby 3.2/3.3/3.4, lint, security, auto-tag release)
62
89
  - Comprehensive documentation and examples
63
90
 
64
- [Unreleased]: https://github.com/stowzilla/lambda-loadout/compare/v0.0.1...HEAD
91
+ [Unreleased]: https://github.com/stowzilla/lambda-loadout/compare/v0.0.4...HEAD
92
+ [0.0.4]: https://github.com/stowzilla/lambda-loadout/compare/v0.0.3...v0.0.4
65
93
  [0.0.1]: https://github.com/stowzilla/lambda-loadout/releases/tag/v0.0.1
data/README.md CHANGED
@@ -366,7 +366,11 @@ bundle exec rake layer:publish
366
366
  bundle exec rake layer:clean
367
367
  ```
368
368
 
369
- The layer targets the `ruby3.4` runtime. After publishing, add the returned `LayerVersionArn` to your Lambda function configuration.
369
+ `layer:build` needs Docker. It installs the gem inside the AWS SAM build image for each supported runtime, so native extensions (`json`, `bigdecimal`) are compiled for Lambda instead of your machine.
370
+
371
+ One layer version works on both `ruby3.4` and `ruby4.0`. Each runtime only loads layer gems from its own directory (`/opt/ruby/gems/3.4.0` or `/opt/ruby/gems/4.0.0`), so the zip contains both. Moving a function from 3.4 to 4.0 doesn't require a new layer ARN. The layer is x86_64 only.
372
+
373
+ After publishing, add the returned `LayerVersionArn` to your Lambda function configuration.
370
374
 
371
375
  ### Shell Scripts (alternative)
372
376
 
@@ -239,7 +239,7 @@ module LambdaLoadout
239
239
  'function_version' => @lambda_context.function_version,
240
240
  'function_memory_size' => @lambda_context.memory_limit_in_mb,
241
241
  'function_request_id' => @lambda_context.aws_request_id,
242
- 'cold_start' => LambdaLoadout.cold_start?
242
+ 'cold_start' => LambdaLoadout.cold_start?(@lambda_context)
243
243
  }.compact
244
244
  rescue StandardError
245
245
  {}
@@ -151,7 +151,7 @@ module LambdaLoadout
151
151
  # @return [void]
152
152
  def add_cold_start_metric(context)
153
153
  return if @cold_start_captured
154
- return unless LambdaLoadout.cold_start?
154
+ return unless LambdaLoadout.cold_start?(context)
155
155
 
156
156
  @cold_start_captured = true
157
157
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LambdaLoadout
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
@@ -91,11 +91,32 @@ module LambdaLoadout
91
91
 
92
92
  # Get cold start status
93
93
  #
94
+ # With a Lambda context, the first invocation this process sees is the cold
95
+ # start, and every call made during that invocation returns true; later
96
+ # invocations return false. Without a context it answers true exactly once.
97
+ #
98
+ # @param context [Object, nil] Lambda context
94
99
  # @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
+ def self.cold_start?(context = nil)
101
+ request_id = context.aws_request_id if context.respond_to?(:aws_request_id)
102
+ return consume_cold_start unless request_id
103
+
104
+ @cold_start_request_id ||= request_id
105
+ @cold_start_request_id == request_id
106
+ end
107
+
108
+ # Forget cold start state, so the next invocation counts as cold again
109
+ #
110
+ # @return [void]
111
+ def self.reset_cold_start!
112
+ @cold_start_request_id = nil
113
+ @cold_start_consumed = false
114
+ end
115
+
116
+ def self.consume_cold_start
117
+ return false if @cold_start_consumed || @cold_start_request_id
118
+
119
+ @cold_start_consumed = true
100
120
  end
121
+ private_class_method :consume_cold_start
101
122
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda_loadout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis
@@ -27,16 +27,22 @@ dependencies:
27
27
  name: json
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - - "<"
31
34
  - !ruby/object:Gem::Version
32
- version: '2.0'
35
+ version: '4'
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
- - - "~>"
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2'
43
+ - - "<"
38
44
  - !ruby/object:Gem::Version
39
- version: '2.0'
45
+ version: '4'
40
46
  - !ruby/object:Gem::Dependency
41
47
  name: logger
42
48
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +105,14 @@ dependencies:
99
105
  requirements:
100
106
  - - "~>"
101
107
  - !ruby/object:Gem::Version
102
- version: '0.22'
108
+ version: '1.2'
103
109
  type: :development
104
110
  prerelease: false
105
111
  version_requirements: !ruby/object:Gem::Requirement
106
112
  requirements:
107
113
  - - "~>"
108
114
  - !ruby/object:Gem::Version
109
- version: '0.22'
115
+ version: '1.2'
110
116
  description: Structured logging, CloudWatch metrics (EMF), error handling, and alerting
111
117
  for AWS Lambda functions. Implement serverless best practices with minimal overhead.
112
118
  email: