'spring function in aws lambda not sending back status code
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.
Solution 1:[1]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user1555190 |
