fix(lambda): Set proper handler return value for lambda as ALB target#1249
Open
ethann wants to merge 1 commit intoAdyen:masterfrom
Open
fix(lambda): Set proper handler return value for lambda as ALB target#1249ethann wants to merge 1 commit intoAdyen:masterfrom
ethann wants to merge 1 commit intoAdyen:masterfrom
Conversation
Lambda in AWS can be configured as Target Group for ALB. API Gateway, Lambda Function URL and Application Load Balancer expect lambda to return an object with specific fields, e.g. 'statusCode' which have a special behavior (response object). Not specifying 'statusCode' field in lambda and triggering it by API Gateway or Function URL converts return object into a string and returns it with status code 200. ALB throws 502 Bad Gateway error instead, expecting lambda to return a proper response object structure with at least 'statusCode' field (the rest including 'body' seems to be optional). To keep it compatible with all three solutions and avoid potential conflict between returned body and response object structure, object returned by the lambda should have a proper structure. To keep it compatible with current behavior, status is set to 200 and the body is stringified and returned as the lambda response object 'body' field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lambda in AWS can be configured as Target Group for ALB. API Gateway, Lambda Function URL and Application Load Balancer expect lambda to return an object with specific fields, e.g.
statusCodewhich have a special behavior (response object). Not specifyingstatusCodefield in lambda and triggering it by API Gateway or Function URL converts return object into a string and returns it with status code 200. ALB throws 502 Bad Gateway error instead, expecting lambda to return a proper response object structure with at leaststatusCodefield (the rest includingbodyseems to be optional).To keep it compatible with all three solutions and avoid potential conflict between returned body and response object structure, object returned by the lambda should have a proper structure. To keep it compatible with current behavior, status is set to 200 and the body is stringified and returned as the lambda response object
bodyfield.API Gateway response body:
https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-types-transforms
Lambda Function url response body (follows API Gateway structure):
https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads
ALB Target group response body:
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#respond-to-load-balancer