Skip to main content

BACKND FUNCTION Template

This is a description of the BACKND Function’s default template.
If you create a project using the BACKND Function template, you can check the following code in Function.cs when initial settings are completed.

Starting with the TODO section, it is possible to write the logic desired by the developer and return the result in the form of a stream.

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

using Amazon.Lambda.Core;
using Newtonsoft.Json.Linq;
using LitJson;

using BackendAPI;
using BackendAPI.Value;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace BackendFunction
{
public class BFunc
{
public Stream Function(Stream stream, ILambdaContext context)
{
try
{
// Initialize BACKND Function API
Backend.Initialize(ref stream);
}
catch(Exception e)
{
// When BACKND Function API initialization fails
return ReturnErrorObject("initialize " + e.ToString());
}

// TODO: Developers can write their own logic here

// When a desired value is returned in the form of a stream, the value is sent to the BACKND SDK.
return Backend.StringToStream("BackendFunction");
}

static Stream ReturnErrorObject(string err)
{
JObject error = new JObject();
error.Add("error", err);

return Backend.JsonToStream(error.ToString());
}
}
}