.NET Core
Overview of creating .NET Core functions
Getting and publishing a function
The following shows how to get, edit, and pack your template for upload.
Versions | Template |
.NET Core 2.1 |
After you have downloaded the template project, unzip it and navigate to
./LambdaFunction
directory and openLambdaFunction.csproj
project (if you are not using an IDE with automated restore functionality, rundotnet restore
in command-line tool inside this folder).Your entry (main) method will be inside
Function.cs
file calledHandler
.After you are done editing your function, open command-line tool inside of
./LambdaFunction
directory and run
dotnet 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.
Template overview
The following explains how to use provided template to create your own functions.
Main method
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.
Inputs
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.
Class | Description |
| Use when executing function through API or using this function in a scheduler task. |
| Use when using this function as a trigger for collections. |
| Use when using this function as a trigger for files. |
| Use when using this function as a trigger for users. |
Getting environment variables
A line below shows how to get the environment variables that you have set up near your function.
Getting app settings
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:
Constructors
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.
Last updated