private static async Task <tResult> WriteStream(tInput oInput, ILambdaContext context) { const string myStreamName = "CloudEcoPlus"; string strInput; string strEncoded; tResult oResult = new tResult(); try { context.Logger.LogLine("Putting records in stream : " + myStreamName); // Write 10 UTF-8 encoded records to the stream. PutRecordRequest requestRecord = new PutRecordRequest(); requestRecord.StreamName = myStreamName; strInput = JsonSerializer.Serialize(oInput); requestRecord.Data = new MemoryStream(Encoding.UTF8.GetBytes(strInput)); context.Logger.LogLine("Putting records in stream 1 : " + myStreamName); strEncoded = Base64Encode(strInput); // just for debug base64 encoding // context.Logger.LogLine("Putting records in stream 2 : " + myStreamName); requestRecord.PartitionKey = "partitionKey"; context.Logger.LogLine("Putting records in stream 3 : " + myStreamName); PutRecordResponse PutRecordResult = await kinesisClient.PutRecordAsync(requestRecord); context.Logger.LogLine("PutRecordResult ok" + PutRecordResult.HttpStatusCode); } catch (Exception ex) { oResult.Ok = false; oResult.Info = ex.Message; context.Logger.LogLine("Error WriteStream "); } context.Logger.LogLine("Putting records in stream 4"); return(oResult); }
// public async Task<tResult> FunctionHandler(tInput oInput, ILambdaContext context) public async Task <tResult> FunctionHandler(tInput oInput, ILambdaContext context) { tResult oResult = new tResult(); context.Logger.LogLine($"Input string:{JsonSerializer.Serialize<tInput>(oInput) }"); try { // Validate here oResult = await WriteStream(oInput, context); // Write to Kinesis context.Logger.LogLine("State 1"); } catch (Exception ex) { oResult.Ok = false; oResult.Info = ex.Message; context.Logger.LogLine("Ex in WriteRecord " + ex.Message); } return(oResult); }