2020-09-29

How do I go about getting the output returned by another function I invoked from the main function?

This will be a bit hard to explain but here we go.

I have an AWS Lambda function that uses youtube-dl to download videos from YouTube, then it uploads it to S3 and returns the S3 link for download. Let's call it function1 for reference.

I connected it to API Gateway, I then discovered that the API Gateway in AWS has a timeout of 29 seconds. That means, if I trigger the Lambda function from the API Gateway with a YouTube URL to download, it will wait for 29 seconds, if it didn't get any output it will timeout, terminating the function with it.

Of course, downloads usually take way more than 29 seconds and this limit is annoying.

I got an idea to fix that, created another Lambda function (function2). I linked it to the API Gateway, so then, I can make an http request to function2 with the YouTube URL, then function2 would invoke function1 passing the URL to it.

However, I'm running into a problem now. How do I get the S3 link that function1 returns?

What happens is, I make a request to function2 with the URL, then it passes it to function1, function2 will return a string saying that it's downloading. However I'm really not sure on how to go about getting the S3 link from the function that downloads the video and then uploads it to S3.

I thought about putting the S3 link in an S3 bucket, but then how does the client know that the function put the link there? The only way I can think of is to make the client make requests over and over to see if the link is there and I honestly really don't want to do unnecessary requests.

Oh, and making function2 wait for a response from function1 when invoking it would defeat the purpose of this workaround.

I'm using Python by the way, if it makes any difference.



from Recent Questions - Stack Overflow https://ift.tt/2G6Skes
https://ift.tt/eA8V8J

No comments:

Post a Comment