Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

96malhar
Copy link
Contributor

@96malhar 96malhar commented May 8, 2024

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 the ILambdaSerializer 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 the JsonSerializer 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.

@96malhar 96malhar requested a review from normj May 8, 2024 18:47
@96malhar 96malhar changed the title WIP: Change response type to Stream when Lambda function is uses APIGateway events WIP: Change response type to Stream when Lambda function uses APIGateway events May 8, 2024
Comment on lines 20 to 29
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();
Copy link
Contributor Author

@96malhar 96malhar May 8, 2024

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +238 to +242
var filePath = $"C:\\codebase\\V3\\snapshots\\{model.GeneratedMethod.ContainingType.Name}.g.cs";
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.Write(sourceText);
}
Copy link
Contributor Author

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.

@96malhar
Copy link
Contributor Author

Closed in favor of #1748

@96malhar 96malhar closed this May 13, 2024
@96malhar 96malhar deleted the kmalhar/stream-response-type branch May 13, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant