-
Notifications
You must be signed in to change notification settings - Fork 499
Expose ILambdaSerializer on ILambdaContext #2378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GarrettBeatty
merged 5 commits into
dev
from
GarrettBeatty/expose-serializer-on-context
May 15, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
69f9619
Expose ILambdaSerializer on ILambdaContext
GarrettBeatty 9c9fdbb
Address PR review feedback
GarrettBeatty b6d5159
Address Copilot PR review feedback
GarrettBeatty eace8c7
PR comments
GarrettBeatty abde653
updates to remove shim
GarrettBeatty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
.autover/changes/6e13a012-1f93-4e55-90b5-d2dd480d086c.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "Projects": [ | ||
| { | ||
| "Name": "Amazon.Lambda.Core", | ||
| "Type": "Minor", | ||
| "ChangelogMessages": [ | ||
| "Add ILambdaSerializer Serializer property to ILambdaContext (default-implemented to null on net8.0+) so user code can access the serializer registered with the runtime" | ||
| ] | ||
| }, | ||
| { | ||
| "Name": "Amazon.Lambda.RuntimeSupport", | ||
| "Type": "Minor", | ||
| "ChangelogMessages": [ | ||
| "Expose the registered ILambdaSerializer on HandlerWrapper.Serializer and propagate it to the per-invocation ILambdaContext.Serializer" | ||
| ] | ||
| }, | ||
| { | ||
| "Name": "Amazon.Lambda.TestUtilities", | ||
| "Type": "Minor", | ||
| "ChangelogMessages": [ | ||
| "Add Serializer setter to TestLambdaContext to mirror the new ILambdaContext.Serializer property" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,14 @@ public class HandlerWrapper : IDisposable | |
| /// </summary> | ||
| public LambdaBootstrapHandler Handler { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// The serializer registered with the wrapper, if any. Surfaced so the | ||
| /// runtime bootstrap can attach it to the per-invocation | ||
| /// <see cref="ILambdaContext"/>, allowing user code to reuse it. | ||
| /// Null for handlers that don't take a typed input/output. | ||
| /// </summary> | ||
| public ILambdaSerializer Serializer { get; private set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
|
||
| private HandlerWrapper(LambdaBootstrapHandler handler) | ||
| { | ||
| Handler = handler; | ||
|
|
@@ -121,7 +129,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, Task> handle | |
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| await handler(input); | ||
| return EmptyInvocationResponse; | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -171,7 +179,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte | |
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| await handler(input, invocation.LambdaContext); | ||
| return EmptyInvocationResponse; | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -218,7 +226,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, Task<Stream> | |
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| return new InvocationResponse(await handler(input)); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -265,7 +273,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte | |
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| return new InvocationResponse(await handler(input, invocation.LambdaContext)); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -278,7 +286,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TOutput output = await handler(); | ||
|
|
@@ -300,7 +308,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Task<TOutput>> hand | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TOutput output = await handler(invocation.InputStream); | ||
|
|
@@ -322,7 +330,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, Task<TOutpu | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
|
|
@@ -345,7 +353,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, Tas | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<ILambdaContext, Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TOutput output = await handler(invocation.LambdaContext); | ||
|
|
@@ -367,7 +375,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<ILambdaContext, Tas | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, ILambdaContext, Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TOutput output = await handler(invocation.InputStream, invocation.LambdaContext); | ||
|
|
@@ -389,7 +397,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, ILambdaCont | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, ILambdaContext, Task<TOutput>> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = async (invocation) => | ||
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
|
|
@@ -449,7 +457,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Action<TInput> handler, I | |
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| handler(input); | ||
| return Task.FromResult(EmptyInvocationResponse); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -499,7 +507,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Action<TInput, ILambdaCon | |
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| handler(input, invocation.LambdaContext); | ||
| return Task.FromResult(EmptyInvocationResponse); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -546,7 +554,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, Stream> hand | |
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| return Task.FromResult(new InvocationResponse(handler(input))); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -593,7 +601,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte | |
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
| return Task.FromResult(new InvocationResponse(handler(input, invocation.LambdaContext))); | ||
| }); | ||
| }) { Serializer = serializer }; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -606,7 +614,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput>(Func<TInput, ILambdaConte | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TOutput output = handler(); | ||
|
|
@@ -628,7 +636,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<TOutput> handler, I | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TOutput output = handler(invocation.InputStream); | ||
|
|
@@ -650,7 +658,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, TOutput> ha | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
|
|
@@ -673,7 +681,7 @@ public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, TOu | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<ILambdaContext, TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TOutput output = handler(invocation.LambdaContext); | ||
|
|
@@ -695,7 +703,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<ILambdaContext, TOu | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, ILambdaContext, TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TOutput output = handler(invocation.InputStream, invocation.LambdaContext); | ||
|
|
@@ -717,7 +725,7 @@ public static HandlerWrapper GetHandlerWrapper<TOutput>(Func<Stream, ILambdaCont | |
| /// <returns>A HandlerWrapper</returns> | ||
| public static HandlerWrapper GetHandlerWrapper<TInput, TOutput>(Func<TInput, ILambdaContext, TOutput> handler, ILambdaSerializer serializer) | ||
| { | ||
| var handlerWrapper = new HandlerWrapper(); | ||
| var handlerWrapper = new HandlerWrapper { Serializer = serializer }; | ||
| handlerWrapper.Handler = (invocation) => | ||
| { | ||
| TInput input = serializer.Deserialize<TInput>(invocation.InputStream); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call out the property is preview. There will be another release where we take the preview flag off once the managed runtime has been deployed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated