Looking to run my Python code on AWS without maintaining a server (not Lambda?)

Hi AWS,

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.

Ecs with fargate could help.

What are the reasons you don’t want to use Lambda here?

I assume the possibility 120 second turn around.

Yeah sounds like you want a Docker container launched in ECS and fargate and managed in ECR.

← 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

You end up paying for the wait time.

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..

That’s technically not a problem. The problem so far has been that API gateway times out an API request made to my API within 30 seconds

Yes, but they are unfortunately unwilling to cooperate. And as a small business owner, I need to integrate their solution.

Sorry, I did read (and mean) 120 seconds - Lambda has a 5 minute timeout.

I think you’ve identified the issue here - you’re attempting to simply proxy them. How about, instead, you be the one to implement callbacks?

Have your API register a request, and call Lambda, then have that Lambda (or a subsequent function) make a callback to the original caller?

Elastic Beanstalk is probably what you’re looking to use. It’s basically AWS’s answer to Heroku.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html

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.

Can you proxy the results? Do they go stale immediately?

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:

  1. Call your lambda through API Gateway. It would return a response immediately and run asynchronously.
  2. 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 :confused:

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.

I cannot cache the results and have it easily ready for people requesting my API. I need to request the third party API to get the correct response.

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!