Why are the properties in my message getting set to null?
When I produce a message to my Kafka topic, I can see the messages with properties assigned in the MSK Kafka UI.
When I print out the serialized message in my function, all of my properties are being set to null:
<code>Received input:
{
"Media": null,
"Season": null,
"Content": null,
"Collection": null,
"Key": null,
"Id": 0,
"Type": null,
"Action": null,
"MD5": null
}
</code>
<code>Received input:
{
"Media": null,
"Season": null,
"Content": null,
"Collection": null,
"Key": null,
"Id": 0,
"Type": null,
"Action": null,
"MD5": null
}
</code>
Received input:
{
"Media": null,
"Season": null,
"Content": null,
"Collection": null,
"Key": null,
"Id": 0,
"Type": null,
"Action": null,
"MD5": null
}
The following is my code:
<code>using Amazon.Lambda.Core;
using System.Xml.Linq;
using IVITransformer.Models;
using Newtonsoft.Json;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
//[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace AWSLambdaIVITransformer;
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input">The event for the Lambda function handler to process.</param>
/// <param name="context">The ILambdaContext that provides methods for logging and describing the Lambda environment.</param>
/// <returns></returns>
public string FunctionHandler(MessageModel input, ILambdaContext context)
{
Console.WriteLine("Received input: " + JsonConvert.SerializeObject(input));
if (input == null)
{
Console.WriteLine("No input provided");
return "No input provided";
}
else if (input.Content == null)
{
Console.WriteLine("No content provided");
return "No content provided";
}
else if (input.Content.ContentId == null )
{
Console.WriteLine("Invalid content id provided");
return "Invalid content id provided";
}
Console.WriteLine("Received inputt: " + input.Content.ContentId.ToString());
return input.Content.ContentId.ToString();
}
}
</code>
<code>using Amazon.Lambda.Core;
using System.Xml.Linq;
using IVITransformer.Models;
using Newtonsoft.Json;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
//[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace AWSLambdaIVITransformer;
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input">The event for the Lambda function handler to process.</param>
/// <param name="context">The ILambdaContext that provides methods for logging and describing the Lambda environment.</param>
/// <returns></returns>
public string FunctionHandler(MessageModel input, ILambdaContext context)
{
Console.WriteLine("Received input: " + JsonConvert.SerializeObject(input));
if (input == null)
{
Console.WriteLine("No input provided");
return "No input provided";
}
else if (input.Content == null)
{
Console.WriteLine("No content provided");
return "No content provided";
}
else if (input.Content.ContentId == null )
{
Console.WriteLine("Invalid content id provided");
return "Invalid content id provided";
}
Console.WriteLine("Received inputt: " + input.Content.ContentId.ToString());
return input.Content.ContentId.ToString();
}
}
</code>
using Amazon.Lambda.Core;
using System.Xml.Linq;
using IVITransformer.Models;
using Newtonsoft.Json;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
//[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace AWSLambdaIVITransformer;
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input">The event for the Lambda function handler to process.</param>
/// <param name="context">The ILambdaContext that provides methods for logging and describing the Lambda environment.</param>
/// <returns></returns>
public string FunctionHandler(MessageModel input, ILambdaContext context)
{
Console.WriteLine("Received input: " + JsonConvert.SerializeObject(input));
if (input == null)
{
Console.WriteLine("No input provided");
return "No input provided";
}
else if (input.Content == null)
{
Console.WriteLine("No content provided");
return "No content provided";
}
else if (input.Content.ContentId == null )
{
Console.WriteLine("Invalid content id provided");
return "Invalid content id provided";
}
Console.WriteLine("Received inputt: " + input.Content.ContentId.ToString());
return input.Content.ContentId.ToString();
}
}
My code works when using the AWS provided test harness (provided by the Lambda Visual Studio project type). I’m able to print out a Content ID. Does anyone know why the values are seemingly being stripped?
Recognized by AWS