Request does not contain domain name information but is derived from APIGatewayProxyFunction

Ingesting CloudWatch logs cost money ($0.57 per GB log data ingested), so removing log lines that are not useful will save you money. In my C# API project the logs are filled with this Warning:

[Warning] Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction: Request does not contain domain name information but is derived from APIGatewayProxyFunction. 

This warning comes from the code found in Amazon.Lambda.AspNetCoreServer APIGatewayHttpApiV2ProxyFunction.cs as shown here: https://github.com/aws/aws-lambda-dotnet/blob/85dd6e164c324120535815e02c30e3ae2e5d72f3/Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayHttpApiV2ProxyFunction.cs#L94-L97

While it is possible to edit the appsettings.json file to stop it outputting Warnings from Amazon.Lambda.AspNetCoreServer component, this would then prevent other useful log lines.

This error messages comes because there is missing information in the payload sent to the Lambda function. Usually when say a Mobile App makes a request to the ApiGateway, the ApiGateway calls the Lambda function and the domain name is populated in the pay load. However when calling the Lambda direct without using ApiGateway as I explain in a previous blog post https://www.daniel-mitchell.com/blog/calling-dotnetcore/ the payload does not have this information.

The fix is then to simply populate this field with any sensible value, it does not even have to be a valid URL. For my use, the following is a sufficient JSON payload that I send into the Lambda function.

{
  "rawQueryString": 'key1=value1',
  "requestContext": {
    "domainName": "INSERT-A-VALUE-HERE",
    "http": {
      "method": "GET",
      "path": "/my/path"
      }
    }
  }
}
Add in a value for requestContext.domainName to avoid generating unnecessary warnings

This eliminates the warning message, and reduces the amount of CloudWatch log data by around 300 characters per request. That's an almost 35% reduction.

Daniel Mitchell

Daniel Mitchell