How do I troubleshoot HTTP 504 errors from my API Gateway REST API?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] [Music] hello i'm nagendra a cloud support engineer here at the aws office in dallas today i am going to discuss troubleshooting steps that can help isolate the reason for 504 errors written by an amazon api gateway rest api let's get started 504 errors can occur when connecting to their service through an api gateway rest api the api gateway rest api has a maximum integration timeout value for any type of integration if the integration backend does not respond to the api gateway within the configure timeout value then api gateway returns a http 504 status code the maximum integration timeout value for the api gateway rest api is 29 seconds which is also the default value to understand the reason for the 504 errors let's first confirm where the request is getting timed out to identify the source of the error we'll use api gateway cloud watch logs to do this we must first enable the amazon cloudwatch logs on the api stage i have the api gateway console open and i have selected my rest api under stages i'll select the stage used for the rest api and then go to the logs or tracing tab here i'll check the box next to enable cloudwatch logs i'll select the info level logging to get logs for all requests also i'll check the log full request or response data to get webos logs in cloudwatch then i'll save these changes when these changes are saved we'll make some new requests to the api to reproduce the errors when the errors are reproduced we can then go to the cloudwatch logs and find the log group created for the api for this video i have simulated a 504 error on my api we can find the api's log group by filtering the api id or this stage name we can get the api id from the api gateway console in the log group we can see the request that returned an error using the timestamp when we open the logs we can check the flow of request as processed by the rest api if the 504 errors are due to the integration endpoint timing out we will see the execution failed due to timeout message after the endpoint request body after transformation and sending request to lines in this case my backend is a lambda function so i'll see the lambda function details in the sending request to step as we can see here the timeout occurred after the sending request to line next we can verify whether the associated backend endpoint is invoked or receiving the request if the backend is a lambda function we can confirm whether this lambda function is invoked or not by checking the invocation metric on the function if the backend is a web server we can check from the server logs whether the request is received if the backend service wasn't invoked or never received the request then consider implementing retries at your client to retry these errors which are most likely a result of a temporary network failure in the api gateway service when sending the request to the integration backend if the backend service receives the request but can't complete processing or not returning a response within the api gateway integration timeout value you can consider these options to help reduce the processing time for example in the backend server keep only the logic required to send a response back to the api gateway if there is any additional code that can be run separately or doesn't require for the response that was sent to the api gateway then consider running this code in a separate service such as lambda by triggering it separately from your integration backend or consider reviewing the backend service or server logic and optimize it where possible to make sure that it completes within the configured integration timeout value it's a best practice to configure the maximum timeout on the backend so that it's less than the integration timeout that's configured on the api gateway however sometimes it's just not possible to reduce the processing code logic or the time on the backend server if that happens and if the backend is a lambda function api gateway provides an option to invoke the lambda function asynchronously when invoked asynchronously the lambda service returns a success response code to the api gateway soon after receiving the request the lambda service processes the actual request in the function separately later this is a good option if api gateway's response to the client isn't dependent on the backend lambda function's execution result to invoke a lambda function asynchronously we will set a custom header x amg invocation type with value set to event in the integration request configuration and now you know several troubleshooting steps that can be used to help isolate the reason for 504 errors returned by an amazon api gateway rest api and some methods to address these errors thanks for watching and happy cloud computing from all of us here at aws [Applause] [Music]
Info
Channel: Amazon Web Services
Views: 6,779
Rating: undefined out of 5
Keywords: AWS, Amazon Web Services, Cloud, AWS Cloud, Cloud Computing, Amazon AWS, AWS Knowledge Center Videos
Id: 9tpE9W-SCZM
Channel Id: undefined
Length: 6min 3sec (363 seconds)
Published: Mon Aug 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.