A company runs a serverless mobile app that uses Amazon API Gateway, AWS Lambda functions, Amazon Cognito, and Amazon DynamoDB. During large surges in traffic, users report intermittent system failures. The API Gateway API endpoint is returning HTTP status code 502 (Bad Gateway) errors to valid requests. How do you resolve this issue?
Sigiloso
○ The API Gateway is most likely returning 502 errors because the Lambda functions are throwing unformatted errors. I would adjust the lambda function to catch all errors, and format them into a proper JSON response. This would allow me to identify the root cause of the issue and properly identify the error as a 500 or a 404 or something else. This error probably only shows its ugly head when there is a high amount of traffic. I would monitor Cloudwatch closely and look for tracebacks and error messages. If there are database read timeouts happening, I could try increasing the time each Lambda function will wait for a response.