private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.None,
MissingMemberHandling = MissingMemberHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
@aabragan We could do like we did for passing in custom converters https://github.com/aws/aws-lambda-dotnet/blob/07ce8b4f06c12e96f357c1647575a63b66d206af/Libraries/test/TestFunctionFSharp/FSharpJsonSerializer/FSharpJsonSerializer.cs
Have a constructor that takes in a JsonSettings. Then you could extend the the serializer and pass your JsonSettings to the base constructor. Then use your serializer in the Lambda serializer attribute.
/// <summary>
/// Constructs instance of serializer.
/// </summary>
public JsonSerializer() : this(null, null)
{
}
/// <summary>
/// Constructs instance of serializer using custom converters.
/// </summary>
public JsonSerializer(IEnumerable<JsonConverter> converters)
: this(converters, null)
{
}
/// <summary>
/// Constructs instance of serializer using custom converters and custom serialization settings.
/// </summary>
public JsonSerializer(IEnumerable<JsonConverter> converters, JsonSerializerSettings settings)
{
if (settings == null)
settings = new JsonSerializerSettings();
settings.ContractResolver = new AwsResolver();
serializer = Newtonsoft.Json.JsonSerializer.Create(settings);
if (string.Equals(Environment.GetEnvironmentVariable(DEBUG_ENVIRONMENT_VARIABLE_NAME), "true", StringComparison.OrdinalIgnoreCase))
{
this.debug = true;
}
if (converters != null)
{
foreach (var c in converters)
{
serializer.Converters.Add(c);
}
}
}
/// <summary>
/// Custom Json Serializer based on Amazon's implementation
/// </summary>
public class CustomJsonSerializer : JsonSerializer
{
private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.None,
MissingMemberHandling = MissingMemberHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
/// <summary>
/// Constructs instance of serializer using custom serialization settings.
/// </summary>
public CustomJsonSerializer() : base(null, SerializerSettings)
{
}
}
Hi there... I use a URL Rewrite to make use a Lambda behind a reverse proxy. (/acme/abc should execute <lambda>/prod/acme/abc). This works fine, but within my code I create an Url with the UrlHelper. Running on my local maschine everything seems to be fine (The link is created as /acme/xyz) but when running within Lamba it ist created as /prod/acme/xyz.
Any Ideas?
Are there any tricks to get the LambdaLogger
to log the request id with every message? The closest I've gotten is by using scopes. This gives me a consistent ID for every message within a request, but this is not the actual requestid
that AWS generates (see below). I've tried turning on EventIDs, but this doesn't appear to do anything useful. I'm on Amazon.Lambda.Logging.AspNetCore 2.3.0.
Example:
START RequestId: 0398a3a7-a36f-47c4-acf8-62baf867b25c Version: $LATEST
[Information] RequestId:0HLQ7DJ3PSAU1...
I'm looking to have both of RequestIDs to be the GUID assigned by AWS.
Hi ... I get an error, while starting my application within the lambda testtool:
System.MissingMethodException: Method not found: 'Microsoft.AspNetCore.Hosting.IWebHostBuilder Microsoft.AspNetCore.Hosting.IWebHostBuilder.ConfigureAppConfiguration(System.Action`2<Microsoft.AspNetCore.Hosting.WebHostBuilderContext,Microsoft.Extensions.Configuration.IConfigurationBuilder>)'.
I have implemented a serverless lambda function which is to be invoked by API Gateway, but I am asked to use WebApi template. I don't understand how would choosing this template would be better. The api gateway SAM configuration any way takes care of hitting that lambda function. Besides, that lamda is simply responsible to insert data into a table.
Kindly enlighten me on questions above and the above scenario considering the best practices.
@normj - what's your thoughts on the following statements?
This page titled "Using Amazon Logging Frameworks with AWS Lambda" describes AWS Lambda logging patterns: https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/cw-log-frameworks.html
But, when you goto any of the links in the last line, "The AWS .NET logging plugins are a new open source project on GitHub. All of the plugins are there, including samples and instructions on how to configure CloudWatch Logs for each of the supported .NET logging frameworks.", they lead you to a project with a readme.md that reads "When using Lambda it is recommended to use either the ILambdaContext.Logger.LogLine or the Amazon.Lambda.Logging.AspNetCore package."
In other words, it seems the bulk of the page "https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/cw-log-frameworks.html" is bad advice, because it is demonstrating a pattern which is not recommended.
I feel as though I have wasted a couple of days because of this because I missed this callout in the readme.md not to use them with AWS Lambda. BTW, wasted days because I couldn't not figure out why the log events were not being written. Ironically, they do seem to get flushed with the next call to the lambda function, so the last set of entries is always missing.
Hi,
Can anyone help me on
-- Custom Header not being added at final HTTP response - APIGatewayHttpApiV2ProxyResponse class from AWS .NET Lambda SDK
Severity Code Description Project File Line Suppression State Tool
Error CS0234 The type or namespace name 'APIGatewayEvents' does not exist in the namespace 'Amazon.Lambda' (are you missing an assembly reference?) TableReadyAWSRestaurantsInfoLambda C:\Users\zhiwe\source\repos\TableReadyAWSRestaurantsInfoLambda\TableReadyAWSRestaurantsInfoLambda\Function.cs 7 Active Compiler