To help you understand better about the function step you can try the following function yourself. The goal of the function is to get awsKeyId and videoUrl parameters from the previous step, then process and return to the next step to make further processing.

1. First, we define the input params for the step:

[
{
key: 'awsKeyId',
require: true,
dataType: 'referenceKey'
},
{
key: 'videoUrl',
require: true,
dataType: 'video'
}
]

Then, define output param:

[
{
key: 'size',
dataType: 'integer'
}
]

2. Add packages (dependencies)

[
'aws-sdk',
'https',
'request'
]

3. Write the code to download the video from S3 and return the downloaded size:

async function main (service, context) {
let fileSize = 0;

await downloadFromS3(service.videoUrl, 'localVideo.mp4').then((result) => {
fileSize = result.length;
});

//return the
return {
size: fileSize
}
}

async function downloadFromS3(srcUrl, dstFile) {
var downloaded = 0;

return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dstFile);
const request = https.get(srcUrl, (response) => {
response.pipe(file);
response.on('data',(chunk) => {
downloaded += chunk.length;
})

file.on('finish', (e) => {
console.log('Saved to: ' + dstFile);
console.log('File length: ' + downloaded);
file.end();
resolve({
fileName: dstFile,
length: downloaded
});
});
});
});
}

module.exports = main;

Did this answer your question?