I'm working on Nodejs Lambda function. It is to fetch remote video file to upload to s3. While it works on the small size file, but large size case fails upon the time limitation of API gateway (29 seconds).
Are there ways that I receive api call back early to the request while the code is running on lambda?
I wrapped the function with Async but it takes same time. Probaly I was wrong at setting for the asynchronous job in Nodejs.
The below is the code.
'use strict';
const fetch = require('node-fetch');
const AWS = require('aws-sdk'); // eslint-disable-line import/no-extraneous-dependencies
const s3 = new AWS.S3();
module.exports.save = (event, context, callback) => {
const url = "some_url";
const Bucket = "recorded-video";
const key = "some_key.mp4"
fetch(url)
.then((response) => {
if (response.ok) {
return response;
}
return Promise.reject(new Error(
`Failed to fetch ${response.url}: ${response.status} ${response.statusText}`));
})
.then(response => response.buffer())
.then(buffer => (
{
s3.putObject({
Bucket: process.env.BUCKET,
Key: key,
Body: buffer,
}).promise();
// then give permission.
}
))
};