SiloCitizen3
SiloCitizen3
CC#
Created by SiloCitizen3 on 2/1/2024 in #help
Safe to use Response.OnCompleted ?
I've inherited a dotnet core codebase, hosted in elastic beanstalk, on linux, using nginx as a reverse proxy. One of the controllers has Response.OnCompleted which I've never encountered before...seems to be documented...seems to be supported, but never seen in any other project I've worked in. Is it safe to use? or is it an absolutely bad idea?
5 replies
CC#
Created by SiloCitizen3 on 12/17/2023 in #help
Developing locally in VSCode for AWS SAM Lambdas with Layers and TS and module imports on Win 10
I'm using VSCode to author Typescript code, that gets transpiled using esbuild into javascript to push up to AWS (this seemingly works fine with the serverless.yaml template I have with the necessary metadata declarations). My issue is the use of layers and doing import {something} from 'some-lambda-layer' in some typescript file, and in order to get my "dry runs" locally (ie - sam build --beta-features ) to work, I had to, in my git bash configured terminal, do export NODE_PATH=~/path/to/where/the/layers/live/dependencies/nodejs so that within my typescript file, the imports worked and the build worked. Is there a better/easier way than manually setting the NODE_PATH env variable, to where the source code is on disk for layer dependencies, other than how I've done it?
1 replies
CC#
Created by SiloCitizen3 on 11/15/2023 in #help
XMl: How to convert IEnumerable<XmlNode> to XmlNodeList ?
XMl: How to convert IEnumerable<XmlNode> to XmlNodeList ?
12 replies
CC#
Created by SiloCitizen3 on 9/15/2023 in #help
✅ async/await Task in an AWS Lambda
Given the following code
var someWorkTasks = Task.Run(async () =>
{
....
});
var someWorkTasks = Task.Run(async () =>
{
....
});
without explicitly doing await someWorkTasks; it is possible that the lambda execution will get cut off/finish before that has a change to complete, right? I'm not insane? I need to explicitly await someWorkTasks; to ensure everything inside it finished, right?
27 replies
CC#
Created by SiloCitizen3 on 9/11/2023 in #help
✅ Using services.PostConfigure<ApiBehaviorOptions> to log Model Validation errors in dotnet6?
Is this a safe implementation to log Model Validation errors in dotnet6?
public static IServiceCollection AddModelBindingErrorLogging(this IServiceCollection services)
{
services.PostConfigure<ApiBehaviorOptions>(options =>
{
var builtInFactory = options.InvalidModelStateResponseFactory;

options.InvalidModelStateResponseFactory = context =>
{
try //dont crash the entire app if we cant run this routine
{
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();

var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
var actionName = descriptor.ActionName;
var controllerName = descriptor.ControllerName;
var logger = loggerFactory.CreateLogger("ModelBindingExceptionLogger");

string methodName = $"{controllerName}Controller-{actionName}";
try
{
logger.LogError($"ModelValidation Errors invoking {methodName}. Details: {JsonConvert.SerializeObject(context.ModelState.Errors())}");
}
catch (Exception ex)
{
logger.LogError(ex, $"Unable to get ModelValidation Errors - {methodName}");
}
}
catch { }
return builtInFactory(context);
};
});
return services;
}
public static IServiceCollection AddModelBindingErrorLogging(this IServiceCollection services)
{
services.PostConfigure<ApiBehaviorOptions>(options =>
{
var builtInFactory = options.InvalidModelStateResponseFactory;

options.InvalidModelStateResponseFactory = context =>
{
try //dont crash the entire app if we cant run this routine
{
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();

var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
var actionName = descriptor.ActionName;
var controllerName = descriptor.ControllerName;
var logger = loggerFactory.CreateLogger("ModelBindingExceptionLogger");

string methodName = $"{controllerName}Controller-{actionName}";
try
{
logger.LogError($"ModelValidation Errors invoking {methodName}. Details: {JsonConvert.SerializeObject(context.ModelState.Errors())}");
}
catch (Exception ex)
{
logger.LogError(ex, $"Unable to get ModelValidation Errors - {methodName}");
}
}
catch { }
return builtInFactory(context);
};
});
return services;
}
21 replies
CC#
Created by SiloCitizen3 on 8/25/2023 in #help
❔ AWS ALB with Lambda target group with dotnet 6 not getting multi value querystring parameters?
Does anyone know all the places that need to be checked, to ensure multi value querystring parameters are making it to a Lambda, from an Application Load Balancer? I verified that the target group has Multi value headers on, but I still dont seem to get the values coming through (just the last querystring arg value in the list). I'm also using AWS for Dotnet, and my "Lambda Entry Point" is inheriting from Amazon.Lambda.AspNetCoreServer.ApplicationLoadBalancerFunction not sure what other "thing" to check. Thank you!
4 replies