I code in Python and have an application that requests a third party. This third party spends between 2-120 seconds to answer and it’s not easy to predict the response time. I know this is weird, but unfortunately, the developers of this third party is not willing to have a callback function (which calls my lambda function back once they have a response for me).
So since I need to use this third party service and they are not willing to change the way they handle requests (keep connection alive until they have computed what I need), I am looking for AWS service which can offer me to run my API (Python with Flask) without me having to maintain security & updates on a server.
I am expecting to call this third party service 500 times a day (365 days a year). Do you guys have a suggestion of which service I should use?
EDIT: Forgot to mention that I do not want to maintain a server because all my resources are serverless. It’s just integration with this third party which is causing a headache. And unfortunately it’s a integration we HAVE to do.
← this question - what’s wrong with Lambda? With a 5 minute execution time out, it sounds like you’d have enough time if the max response time is 120ms
It’s not 120ms, it’s 120 seconds. API gateway has a timeout of 30 seconds, so people calling my API won’t get an answer from me because API gateway will timeout the request
So you’re proxying their (crappy) API through your API gateway? If a callback function won’t work, can’t they perhaps at least cache their results - so you call their API, indicating that you’re interested in the response to that API call. Then you call it again later, and now their API has cached the results - so you get the computed results back immediately.
You said you are going to be calling this third party service 500 times a day. So that’s call every 2,88 minutes or 173 seconds. And their API can take up to 120 seconds to compute. It almost sounds like you want realtime updates to data that is computationally expensive..
Sure, but at the scale the OP said (500 per day * 60 secs average) he’s talking about something running for only about 1/3 of the time - not a lot of money for a Lambda function, especially if it’s slimline.
So you are calling your API through API Gateway? In that case you certainly could use lambda if you implemented a callback function for your API.
You would:
Call your lambda through API Gateway. It would return a response immediately and run asynchronously.
Your lambda would wait for the third party response, then make a callback, or push the response in a Queue, or in a DB, whatever best fits your use case.
I know you want to avoid Lambda BUT you could avoid API Gateway entirely and directly invoke the lambda using the SDK. The timeout would then be whatever the max execution time of the lambda is. We do this a lot at work because we don’t want to pay for API Gateway and it appears to have some latency when running inside a VPC.
I’m not sure how expensive a Lambda will be over this time period. Can’t you call their API with a Lambda, store the API response somewhere (on S3 as text?), and then when someone calls your Api Gateway - instead of proxying their API, you read the API response from S3. So you basically create your own cache of their API. I guess this will only work if the API requests your going to be making to their API is consistently the same
Just putting the idea out there. Someone also mentioned Elastic Beanstalk. I haven’t worked with Elastic Beanstalk to know how many resources that spins up and what it can potentially cost.
This is exactly what I thought I would end up doing. I am really familiar with AWS Lambda and would like to keep using that instead of launching other AWS services (if not needed). I need to do some more research on what the other people have suggested to make a proper decision. Thank you for your reply!