0

Currently I'm switching from AWS API Gateway to Application Load Balancer for supporting calls to my Lambda function. While API Gateway response contains all data, including "statusCode", the ALB returns only "body". Is there any way to make ALB return "statusCode" as well?

Maybe it has something to do with the response header. I have it set up as:

"headers": { "Content-Type": "application/json" }

The language of Lambda is JavaScript. The ALB rule is set to "Forwarding". Protocol is HTTP.

smigiel
  • 11
  • 1
  • Is there any reason why you can't have API->Lambda, instead of API->ALB->Lambda? – Marcin Sep 30 '20 at 12:35
  • All HTTP responses are going to contain a status code header. Can you explain in more detail why you think the responses from your ALB do not contain an HTTP status code? – Mark B Sep 30 '20 at 12:39
  • 1
    @Marcin they are replacing API Gateway with an ALB, not adding an ALB behind API Gateway. – Mark B Sep 30 '20 at 12:40
  • @MarkB Thanks, I misread the question. – Marcin Sep 30 '20 at 12:43
  • @MarkB, The difference in responses can be seen with curl requests. When I do: curl --header "Content-Type: application/json" --request GET http://my-load-balancer.region.elb.amazonaws.com/target I get response: {“objects”:[“1”, “2”]} But with API-Gateway i get: {"statusCode":200,"body":{“objects”:[“1”, “2”]}} – smigiel Sep 30 '20 at 12:53
  • That actually looks like you were building the response body incorrectly for API Gateway, or you had some non-standard response mapping inside your API Gateway configuration. Why do you want the response to look this way? Why not just check the `Status` HTTP header in the response? Add your code to the question if you want detailed help. – Mark B Sep 30 '20 at 13:04
  • 1
    @MarkB, you may be right that there was something strange with API Gateway response that it included statusCode in the response "body". I think I'll just need to change the way I consume the request in my app and I'll be fine with ALB. Thanks – smigiel Sep 30 '20 at 13:26

0 Answers0