private static async Task <tResult> WriteStream(tInputItem 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) { tResult oResult = new tResult(); int intIdx; context.Logger.LogLine($"Input string:{JsonSerializer.Serialize<tInput>(oInput) }"); try { context.Logger.LogLine("Passed " + oInput.PropertyList.Count.ToString()); for (intIdx = 0; intIdx <= oInput.PropertyList.Count - 1; intIdx++) { oResult = await WriteStream(oInput.PropertyList[intIdx], context); // Write to Kinesis if (oResult.Ok == false) { break; } } // Validate here 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); }