-
Notifications
You must be signed in to change notification settings - Fork 478
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
WIP: Change response type to Stream when Lambda function uses APIGateway events #1746
Conversation
var services = new ServiceCollection(); | ||
|
||
// By default, Lambda function class is added to the service container using the singleton lifetime | ||
// To use a different lifetime, specify the lifetime in Startup.ConfigureServices(IServiceCollection) method. | ||
services.AddSingleton<ComplexCalculator>(); | ||
services.AddSingleton<Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer>(); | ||
|
||
var startup = new TestServerlessApp.Startup(); | ||
startup.ConfigureServices(services); | ||
serviceProvider = services.BuildServiceProvider(); |
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.
The TestServerlessApp contains a Startup
class and this is why the function uses DI. I am not sure why did it not generate these parts in our existing snapshots
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.
Nevermind, this was because we never included the Startup.cs
file in the initial sources for the ComplexCalculator
snapshot test - https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs#L217
We do that for the SimpleCalculator
snapshot test - https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs#L139
var filePath = $"C:\\codebase\\V3\\snapshots\\{model.GeneratedMethod.ContainingType.Name}.g.cs"; | ||
using (StreamWriter writer = new StreamWriter(filePath)) | ||
{ | ||
writer.Write(sourceText); | ||
} |
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.
This was my hack to update the snapshots quickly. Ignore this for now.
Closed in favor of #1748 |
This is WIP
I have only changed a few snapshot files to get a soft approval from reviewers on the approach I am taking.
Issue #, if available:
DOTNET-7459
Description of changes:
This PR changes the response type to
System.IO.Stream
when the Lambda function is configured to use APIGateway events. The result from the customer's Lambda function will be serialized using theILambdaSerializer
implementation specified via the assembly level or the method level attribute. The generated Lambda function will wrap this result in an APIGateway response type and will be serialized into a stream via theJsonSerializer
class. This is done so that any custom serialization options do not conflict with the serialization requirements of the APIGateway response type.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.