AWS Lambda cannot POST json without application/json header in the Request

1 week ago 11
ARTICLE AD BOX

I am working with AWS Lambda functions and I’m having an issue with getting the POST request sent to the Lambda function.

I found that with PostMan I can add a Content-Type application/json header and it all works as it should — the request is seen by Lamda code and processed correctly.

I’ve run the AWS Lambda remote debugger and I can see that the request object is null when the Content-type application/json header is absent.

Is there a way to add this header to my request from within the AWS Lambda framework?

Am I doing something wrong?

I’ve created a class representing the object I want to pass in JSON format.

public class Order { public int id; public String itemName; public int quantity; public Order() { } public Order(int id, String itemName, int quantity) { this.id = id; this.itemName = itemName; this.quantity = quantity; } }

If I just send the JSON without the Content-Type application/json, the code will throw a JSON exception as shown below:

2026-01-27T13:58:59.678Z argument "content" is null: java.lang.IllegalArgumentException java.lang.IllegalArgumentException: argument "content" is null at com.fasterxml.jackson.databind.ObjectMapper._assertNotNull(ObjectMapper.java:4980) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3739) at helloworld.CreateOrderLambda.createOrder(CreateOrderLambda.java:13) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source)

With PostMan, I put the Content-Type application/json header in, and the POST request was successful.

My Lambda Java code is shown below:

package helloworld; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class CreateOrderLambda { public APIGatewayProxyResponseEvent createOrder(APIGatewayProxyRequestEvent request) throws JsonMappingException, JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); Order order = objectMapper.readValue(request.getBody(), Order.class); String responseMessage = String.format("Order created: ID=%d, Item=%s, Quantity=%d", order.id, order.itemName, order.quantity); return new APIGatewayProxyResponseEvent().withStatusCode(200).withBody(responseMessage); } }

The template.yaml:

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: > scratch Sample SAM Template for scratch # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst Globals: Function: Timeout: 20 MemorySize: 512 Resources: HelloWorldFunction: Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction Properties: CodeUri: HelloWorldFunction Handler: helloworld.CreateOrderLambda::createOrder Runtime: java25 Architectures: - x86_64 MemorySize: 512 Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object Variables: PARAM1: VALUE Events: HelloWorld: Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api Properties: Path: /order Method: POST Outputs: # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function # Find out more about other implicit resources you can reference within SAM # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api HelloWorldApi: Description: "API Gateway endpoint URL for Prod stage for Hello World function" Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/Prod/order/" HelloWorldFunction: Description: "Hello World Lambda Function ARN" Value: !GetAtt HelloWorldFunction.Arn HelloWorldFunctionIamRole: Description: "Implicit IAM Role created for Hello World function" Value: !GetAtt HelloWorldFunctionRole.Arn
Read Entire Article