0

I had the following code working and returning a statusCode.

        final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        responseEvent.setHeaders(Map.of(CONTENT_TYPE, APPLICATION_JSON));
        responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
        responseEvent.setStatusCode(200);

However i have recently updated the spring function adapter to 3.2.3, and i no longer recieve the status code in the response. In fact the response is now just the body.

My setup is aws lambda using spring function, behind api gateway.

user1555190
  • 2,803
  • 8
  • 47
  • 80

1 Answers1

0

this works.

final APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();
        final Map<String, Object> headers = new HashMap<>();
        headers.put(CONTENT_TYPE, APPLICATION_JSON);
        final ObjectMapper objectMapper = new ObjectMapper();
  responseEvent.setBody(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
            responseEvent.setStatusCode(HttpStatus.OK.value());
        Message<APIGatewayProxyResponseEvent> finalResponse = new GenericMessage<>(responseEvent, headers);
user1555190
  • 2,803
  • 8
  • 47
  • 80