3
votes

I have a Lambda function that I'm calling using API gateway. When the Lambda hits the spawn call on a child_process object the API Gateway immediately fails with a 504 timeout error. My timeout setting on the the API gateway is the max 30 seconds and the Lambda is set for a minute. It only takes up to 1400ms for the lambda to run, but it still reports timeout in the API. The Lambda runs successfully after the API Gateway gets the 504.

This happens during a call to FFMPEG and to a call to resize an image with the Sharp library. This happens whether I use synchronous or asynchronous calls.

function resizeVideo(next) {
    var ffmpegOutput = exec.spawnSync('ffmpeg', [
        '-i', tmpFilePath,
        '-f', 'image2',
        '-frames:v', '1',
        '-filter:v', 'scale=w=-1:h=' + MAX_HEIGHT + ":force_original_aspect_ratio=decrease",
        'pipe:1'
    ]);

    console.log(ffmpegOutput.stderr);

    next(null, JPG_CONTENT_TYPE, ffmpegOutput.stdout);
}

Any thoughts would be appreciated. Thanks!

1
Perhaps there's an error in exec.spawnSync and the type of error just isn't propagated correctly? wrap exec.spawnSync in a try-catch and find out. - Geert-Jan
Tried adding try/catch, but the Lambda is executing properly. No errors were caught. The FFMPEG call results in a successful execution. - aokelly
What's in the API Gateway log? - Michael - sqlbot
There's not a lot in the logs that look useful and they're too long to post here in the comments. It's mostly preamble for setting up the call to the API, then this 23:26:01 Sending request to https://<<LAMBDA ARN>> 23:26:01 Execution failed due to a timeout error 23:26:01 Method completed with status: 504 - aokelly

1 Answers

0
votes

OP's co-worker here. We got this working and I just wanted to post in case it ever helps somebody else with this issue. My understanding is that this was occurring because the timeout had mistakenly been set to a low number (180), mistakenly thinking that number was seconds. We updated the timeout (to the max of 29000) after realizing the value should be specified in milliseconds, but didn't realize we had to "Deploy" the API in order for the change to take effect. After re-deploying the API, the issue was resolved.