.NET Core
Overview of creating .NET Core functions
Last updated
Overview of creating .NET Core functions
Last updated
The following shows how to get, edit, and pack your template for upload.
After you have downloaded the template project, unzip it and navigate to ./LambdaFunction
directory and open LambdaFunction.csproj
project (if you are not using an IDE with automated restore functionality, run dotnet restore
in command-line tool inside this folder).
Your entry (main) method will be inside Function.cs
file called Handler
.
After you are done editing your function, open command-line tool inside of ./LambdaFunction
directory and rundotnet publish -o lambda
.
Navigate to a newly created folder ./lambda
and zip all the contents inside of the directory.
Upload zipped file to CodeMash.
For the handler, you have to specify your entry function location. Handler follows such format - assembly::namespace.className::methodName
. Following the structure given in the initial template, the handler would be LambdaFunction::LambdaFunction.Function::Handler
. You can edit any of these parameters for your own function.
The following explains how to use provided template to create your own functions.
You define your main function in the handler field. In this case, the main method is Handler
. It takes two parameters - input from CodeMash and function configuration.
CodeMash will always return CustomEventRequest
as an input object. This class takes in generic parameter defining one of the possible input type. The following table explains when to use each of the provided inputs.
A line below shows how to get the environment variables that you have set up near your function.
If you want to userappsettings.json
file the following shows how to read a file. In this case, file is in root directory of a project.
Example of a appsettings.json
file:
Then to get a string from settings:
Lambda executor will call your default constructor (without parameters). If you want to add dependency injection to your services, you will have to add a default constructor which calls your wanted constructor.
Versions
Template
.NET Core 2.1
Class
Description
BasicInput
Use when executing function through API or using this function in a scheduler task.
CollectionTriggerInput
Use when using this function as a trigger for collections.
FileTriggerInput
Use when using this function as a trigger for files.
UserTriggerInput
Use when using this function as a trigger for users.