Skip to content

Design Doc: Lambda Annotation #961

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

Closed
wants to merge 1 commit into from
Closed

Conversation

normj
Copy link
Member

@normj normj commented Nov 8, 2021

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.

  • LambdaFunction attribute triggers source generator and syncs with CloudFormation template
  • LambdaStartup attribute identifies the type that will be used to configure DI
  • Containing Lambda function class's constructor created injecting services from DI
  • HttpApi & RestApi attributes configure Lambda function and CloudFormation with API Gateway as the event source
  • FromHeader attribute maps method parameter to HTTP header value
  • FromQuery attribute maps method parameter to HTTP query string value
  • FromBody attribute maps method parameter to HTTP request body
  • FromRoute attribute maps method parameter to HTTP resource path segment
  • FromService attribute maps method parameter to service registered with DI. Services will be created from DI using scope for the method invocation.
  • 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
  • Add opt-in diagnostic information to help troubleshoot
  • Determine Lambda runtime based on TargetFramework of the project
  • Add YAML support
  • 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.

* An experience similar to what .NET developers are used in frameworks like ASP.NET Core
* Although it will follow similar patterns we will not reuse the same classes as ASP.NET Core to avoid an implicit contract agreement between the developer and the framework.
* No significant impact to cold start
* Measuring with a prototype the plus math operation cold start was in the **~320ms** the same as the basic Lambda programming model. Using ASP.NET Core the cold start was **~1,200ms**.

Choose a reason for hiding this comment

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

I'd love to see the cost breakdown here (hosting bootup, starting the server, MVC).

@96malhar
Copy link
Contributor

Closing this PR and the list of supported/planned feature is captured in the design doc via #1613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations feature-request A feature should be added or improved. p1 This is a high priority issue queued
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants