aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Invoke Lambda via Http API inside Lambda Test Tool

Open ggaller opened this issue 3 years ago • 8 comments

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

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Targeted .NET Platform

.NET 6

Operating System and version

Windows, Linux, MacOS

ggaller avatar Oct 25 '22 06:10 ggaller

@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.

ashishdhingra avatar Oct 25 '22 16:10 ashishdhingra

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.

ggaller avatar Oct 26 '22 14:10 ggaller

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

ashishdhingra avatar Oct 27 '22 21:10 ashishdhingra

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

ggaller avatar Oct 28 '22 12:10 ggaller

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

ggaller avatar Dec 09 '22 09:12 ggaller

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!

ggaller avatar Jan 24 '23 08:01 ggaller

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

jeroenvervaeke avatar Mar 15 '23 11:03 jeroenvervaeke

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

ggaller avatar Mar 15 '23 12:03 ggaller