Lambda response is ignored when using Function URL (.NET)

0

I've run into an issue where my .NET AWS Lambda function handler, which is set up to be accessible via the Lambda Function URL feature rather than API Gateway, is ignoring the APIGatewayHttpApiV2ProxyResponse I'm returning. It always responds with the original request body and the Content-Type header value of application/json.

I have exactly one line of code that can possibly write to the log in this function handler, followed by a straightforward response, not throwing any exceptions or anything:

var result = JsonConvert.DeserializeObject<DncInResponse>(responseString);
if (!result.success) LambdaLogger.Log("DNC callback failed: " + result.message);

return new APIGatewayHttpApiV2ProxyResponse() { Body = responseString, Headers = new Dictionary<string, string> { { "content-type", "text/xml" } }, StatusCode = 200, IsBase64Encoded = false };

(Putting aside the fact that I'm returning text/xml at the moment for what should be a JSON response... I tried several different response bodies, content types that match the body, and also capitalized Content-Type.)

My DNC callback failed message appears in CloudWatch when I send a POST or GET request to the appropriate URL, so it's definitely executing the function handler up to the return statement.

I tried it with [assembly: LambdaSerializer(DefaultLambdaJsonSerializer)], [assembly: LambdaSerializer(Amazon.Lambda.Serialization.Json.JsonSerializer)] as it's done here (except with APIGatewayHttpApiV2ProxyResponse as the response type) and with SourceGeneratorLambdaJsonSerializer and the partial class and attributes as described here. I'm also using the latest version of every included NuGet package.

dpmm
asked 8 months ago318 views
1 Answer
0

I translated this lambda function line-for-line to JavaScript, and it works fine. I really want to say this is a bug in the AWS SDK for .NET or whatever's behind that, but I'd be surprised if nobody else ran into it until now.

The JavaScript version of the return value:

    return {
        statusCode: 200,
        headers: {"content-type": "text/xml"},
        body: "<a bunch of irrelevant XML>",
    };
dpmm
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions