aws / aws-lambda-dotnet

Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Apache License 2.0
1.56k stars 480 forks source link

Invoke Lambda via Http API inside Lambda Test Tool #1343

Open ggaller opened 1 year ago

ggaller commented 1 year ago

Describe the feature

Adding http API to Lambda Test Tool as another way to call the function, along with web interface and CLI.

Use Case

In our games we build the server part on the Lambda function. With HTTP endpoint we could write a mock client and connect to the function running from the IDE with the possibility of debugging. It would be a normal local server listening on localhost.

Proposed Solution

I prepared a simple example that works. This is a controller with route to execute endpoint. It used injected LocalLambdaOptions and select default LambdaConfigInfo from it. Right now only payload is passed, but maybe we need to extend the api to be able to specify the function that we need to execute.

Other Information

No response

Acknowledgements

AWS .NET SDK and/or Package version used

-

Targeted .NET Platform

.NET 6

Operating System and version

Windows, Linux, MacOS

ashishdhingra commented 1 year ago

@ggaller Thanks for submitting the feature request. This appears to be duplicate of https://github.com/aws/aws-lambda-dotnet/issues/1279 (which is also reviewed by the team). Please review and confirm if this ticket could be closed as duplicate.

ggaller commented 1 year ago

Hi @ashishdhingra! I looked at the #1279 and it seems to be a similar, but much more complex. I know that the AWS team often implements services with partially overlapping functionality to better meet customer needs and maybe this is the case)) My solution serves to support compatibility with Lambda Invoke API no more and no less. By adding a controller with these endpoints:

[HttpPost("execute")]
public async Task<IActionResult> ExecuteFunction()
{...}

[HttpPost("execute/{functionName}")]
[HttpPost("2015-03-31/functions/{functionName}/invocations")]
public async Task<object> ExecuteFunction(string functionName)
{...}

Lambda Test Tool will be support for the standard lambda client from the AWS SDK like this:

var client = new AmazonLambdaClient(new AmazonLambdaConfig
{
    EndpointProvider = new StaticEndpointProvider("http://localhost:5050/invokeapi/")
});

With support of transferring not only payload, but also logs (LogType.Tail) and errors similar like we get response from AWS.

What do you think of this approach?

Code is ready and I could have a PR ready tomorrow.

ashishdhingra commented 1 year ago

@ggaller Thanks for your response. Feel free to submit the PR which could be reviewed by the team.

ggaller commented 1 year ago

@ashishdhingra PR #1349 is ready and waiting for the team's decision.

ggaller commented 1 year ago

Hi @ashishdhingra. Any chance that the team looks at this issue and related PR?

ggaller commented 1 year ago

Hi @normj! I really appreciate what you do for .NET and enjoy using your tools. I also realise that you have a lot of tasks, but maybe you can spare a few minutes for this issue and related PR. This is a very simple but important functionality that practically blurs the line between classic server-side solutions and the Lambda-based solution for local development and debugging. We are now in the process of deciding how we want to start using local debugging and sharing it with our partners. The alternatives are to release a nuget package with a fork of Lambda Test Tool or release a trimmed nuget package just for debugging, but I would really like to have a single Lambda Test Tool that could be developed by AWS and the community together. I hope to hear from you and have a nice day!

jeroenvervaeke commented 1 year ago

Hi @ggaller, Thank you for your contribution. I have one small remark, but besides that it looks good to me.

ggaller commented 1 year ago

Hi @jeroenvervaeke, Thank you for your review. Added fix by your comments