-
Notifications
You must be signed in to change notification settings - Fork 70
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's figure out what happens for unusual status codes. Then this looks good to merge!
🙏
bootstrap
Outdated
$isALB = array_key_exists("elb", $event['requestContext']); | ||
if ($isALB) { // Add Headers For ALB | ||
$status = $response["statusCode"]; | ||
$response["statusDescription"] = "$status ". $http_codes[$status]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the status code isn't in http_codes
? I think PHP would throw an error.
Maybe only append the http_codes
message if the status exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @txase We could put it inside a try statement
example:
try {
$response["statusDescription"] = "$status ". $http_codes[$status];
} catch (Exception $e) {
$response["statusDescription"] = "$status Unknown"
}
Something like that what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this:
if (array_key_exists($status, $http_codes)) {
$response["statusDescription"] = "$status ". $http_codes[$status];
} else {
$response["statusDescription"] = "$status Unknown";
}
I think it's better to check for conditions explicitly rather than capture all errors (including those you didn't mean to capture).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems great to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, can you update the PR and test it out? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and tested. Everything worked great.
I Couldnt find any HTTP code to test the unknown status code, but in theory it should work withou an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 🤘
Adding Support for PHP to output directly to an ALB
Checked Here:
https://aws.amazon.com/pt/blogs/networking-and-content-delivery/lambda-functions-as-targets-for-application-load-balancers/
We need to add isBase64Encoded= false and the statusDescription to the Response in order to ALB to accepts it as a valid response and not give us 502.
The problem is that if we always add, Api Gateway complains and throws us an error :)
With this little code, everything works seamlessly(with multiValueHeaders enabled in the ELB Target group) without the user have the need to worry. It supports Api Gateway + ALB (If someone want to do some endpoints in ALB directly to save some Api Gateway Requests)
Hope you enjoy