Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Amazon.Lambda.Core;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
- namespace LambdaDemo.ProxyLambda
- {
- public class Function
- {
- public string FunctionHandler(InputModel input, ILambdaContext context)
- {
- Console.WriteLine($"input: {input.ToJson()}");
- var output = new OutputModel()
- {
- UserId = input.UserId,
- UserName = "BEACHSIDE" //とりあえず...
- };
- return output.ToJson();
- }
- }
- // 入力用 model
- public class InputModel : BaseDemoModel
- {
- public string UserId { get; set; }
- }
- // 出力用 model
- public class OutputModel : BaseDemoModel
- {
- public string UserId { get; set; }
- public string UserName { get; set; }
- }
- // キャメルケースでjsonを返すためだけの base class
- public abstract class BaseDemoModel
- {
- private static readonly JsonSerializerSettings Settings;
- static BaseDemoModel()
- {
- Settings = new JsonSerializerSettings
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- };
- }
- public virtual string ToJson() => JsonConvert.SerializeObject(this, Settings);
- }
- }
Add Comment
Please, Sign In to add comment