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

Design Doc: Lambda Annotation

Open normj opened this issue 4 years ago • 0 comments

This PR is for comments on a new .NET Lambda high level library to simplify writing .NET Lambda functions and make the experience more idiomatic.

The high level overview of this library is to use .NET source generator support to translating from the low level single event object programming model of Lambda to an experience similar to ASP.NET Core but with minimal overhead. The initial work is focused on REST API Lambda functions but the technology is applicable for other Lambda event types.

For example users will be able to write a Lambda function like the following with the ICalculator service being injected by dependency injection and and the LambdaFunction and HttpApi attributes directing the source generator to generator the compatible Lambda boiler plate code and sync with the CloudFormation template.

public class Functions
{
	ICalculator _calulator;

	public Functions(ICalculator calculator)
	{
		_calulator = calculator;
	}

	[LambdaFunction]
	[HttpApi(HttpMethod.Get, HttpApiVersion.V2, "/add/{x}/{y}")]
	public int Add(int x, int y)
	{
		return _calulator.Add(x, y);
	}
}

Link to rendered version of the design is here

Development is happening on the feature/annotations branch. Dev builds can be found in the repo's configured Source Generator CI action. Development is very active and breaking changes are to be expected at this stage.

Here is a list of tasks for implementation in no particular priority order. The list will grow as we get deeper into implementation.

  • [x] LambdaFunction attribute triggers source generator and syncs with CloudFormation template
  • [x] LambdaStartup attribute identifies the type that will be used to configure DI
  • [x] Containing Lambda function class's constructor created injecting services from DI
  • [x] HttpApi & RestApi attributes configure Lambda function and CloudFormation with API Gateway as the event source
  • [x] FromHeader attribute maps method parameter to HTTP header value
  • [x] FromQuery attribute maps method parameter to HTTP query string value
  • [x] FromBody attribute maps method parameter to HTTP request body
  • [x] FromRoute attribute maps method parameter to HTTP resource path segment
  • [x] FromService attribute maps method parameter to service registered with DI. Services will be created from DI using scope for the method invocation.
  • [x] Return 400 bad request for Convert.ChangeType failures
  • [ ] Make configurable the location of CloudFormation template to sync with
  • [ ] Add S3 event support
  • [ ] Add DynamoDB event support
  • [ ] Add SQS event support
  • [ ] Add ScheduleTask support
  • [ ] Disable CloudFormation sync
  • [ ] Write metadata file of collected by source generator to JSON file obj folder for users of third party tools to know what is the correct function handler string
  • [x] Add opt-in diagnostic information to help troubleshoot
  • [ ] Determine Lambda runtime based on TargetFramework of the project
  • [x] Add YAML support
  • [x] Add support for image based Lambda functions

Please feel free to comment on the design doc in this PR. That includes direct comments on the design or additional feature requests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

normj avatar Nov 08 '21 08:11 normj