0

i have a python api that i have tried on vms, fargate, and lambda.

vms - less errors when capacity is large enough

fargate - second less errors when capacity is large enough, but when autoscaling, i get some 500 errors. looks like it doesn't autoscale quick enough.

lambda - less consistent. when there are a lot of api calls, less errors. but from cold start, it may periodically fail. i do not pre-provision. when i do, i get less errors too.

i read on the below post, cold start for lambda is less than 1 sec? seems like it's more. one caveat is that each lambda function will check for an existing "env" file. if it does not exist, it will download from s3. however this is done only when hitting the api. the lambda function is listening and responding. when you hit api, the lambda function will respond and connect, download the .env file, and process further the api call. fargate also does the same, but less errors again. any thoughts?

i can pre-provision, but it gets kind of expensive. at that point, i might as will go back to VMs with autoscaling groups, but it's less cloud native. the vms provide the fastest response by far and harder to manage.

Can AWS Lambda coldout cause API Gateway timeout(30s)?

i'm using an ALB in front of lambda and fargate. the vms simply use round robin dns.

questions:

  1. am i doing something wrong with fargate or lambda? are they alright for apis or should i just go back to vms?

  2. what or who maintains api connection while lambda is starting up from a cold start? can i have it retry or hold on to the connection longer?

thanks!

Gary Leong
  • 199
  • 1
  • 2
  • 12

1 Answers1

0

am i doing something wrong with fargate or lambda? are they alright for apis or should i just go back to vms?

The one thing that strikes me is downloading env from s3. Wouldn't it be easier and faster to keep your env data in SSM Parameter Store? Or perhaps, passing them as env variables to the lambda function itself.

what or who maintains api connection while lambda is starting up from a cold start? can i have it retry or hold on to the connection longer?

API gateway. Sadly you can't extend 30 s time limit. Its hard limit.

i'm using an ALB in front of lambda and fargate.

It seems to me that you have API gateway->ALB->Lambda function. Why would you need ALB in that? Usually there is no such need.

i can pre-provision, but it gets kind of expensive.

Sadly, this is the only way to minimize cold-starts.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • thanks for the comments. i actually initially used SSM, but from what i read online ppl just started using s3 instead as a more standard and cheaper alternative. the env file from s3 is essentially encrypted token. i have since moved it to dynamodb to see if that would help. – Gary Leong Aug 10 '21 at 23:00
  • sorry, i mean i used an ALB -> lambda. there is no api gateway. – Gary Leong Aug 10 '21 at 23:01
  • @GaryLeong You can use SSM Parameter Store. It is free. – Marcin Aug 13 '21 at 07:28