Live data from Hacker News

Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

aws.amazon.com

41–50 of 140 posts

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#41
I'm always surprised at the lack of discussion around database connection reuse with AWS Lambda.

It's a pretty big deal that every single API call requires a new database connection. The only solutions I've seen so far are to run a separate app to interface with the database, or moving the connection outside of the handler (which still has issues).

Am I missing something or is everyone just really happy to use DynamoDB?

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#42
post #11

I love lambda's, but api gateway was far from mature the last time I used it (6 months ago). Unless they have made serious updates to the deployment workflow, feature set, and documentation I would not recommend building your products on it.

I'd recommend checking back in for a hot minute every few months or so. The development velocity on this service is pretty rapid. https://aws.amazon.com/blogs/aws/category/amazon-api-gateway...

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#43

I'm always surprised at the lack of discussion around database connection reuse with AWS Lambda. It's a pretty big deal that every single API call requires a new database connection. The only solutions I've seen so far are to run a separate app to interface with the database, or moving the connection outside of the handler (which still has issues). Am I missing something or is everyone just really happy to use Dynamo…

If you design your correctly (at least in Python), you can cache and reuse your open database connection.

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#44
post #43

I'm always surprised at the lack of discussion around database connection reuse with AWS Lambda. It's a pretty big deal that every single API call requires a new database connection. The only solutions I've seen so far are to run a separate app to interface with the database, or moving the connection outside of the handler (which still has issues). Am I missing something or is everyone just really happy to use Dynamo…

If you design your correctly (at least in Python), you can cache and reuse your open database connection.

How exactly have you been doing that? It would be a cool blog post if you had the time. I've been thinking about really high volume applications that connect to haproxy instances that do DB load balancing but even that has it's own set of initial latency issues. I haven't fully figured out that architecture. In python in particular I'd really love to know how to setup the connection reuse.

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#45
post #2

Can you achieve competitive latency for web pages using API Gateway and Lambda?

I was curious about the same thing and setup a jvm lambda to test. The setup was served through API gateway, connected to a postgres RDS, selected a couple records from a single database table and returned them as json, and deployed in us-west. From the west coast, I'm getting between 150ms and 300ms response times for most requests, but it does jump around quite a bit, with occasional requests taking 500ms-800ms to…

Connection would only be pooled on a per-instance basis, which can be cached but sometimes are not for many parallel running processes (to my understanding).

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#47

I'm always surprised at the lack of discussion around database connection reuse with AWS Lambda. It's a pretty big deal that every single API call requires a new database connection. The only solutions I've seen so far are to run a separate app to interface with the database, or moving the connection outside of the handler (which still has issues). Am I missing something or is everyone just really happy to use Dynamo…

One way to do it is to stand an http rest API middle layer in between with something like http://postgrest.com.

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#48
post #44
post #43

Earlier quoted context omitted.

If you design your correctly (at least in Python), you can cache and reuse your open database connection.

How exactly have you been doing that? It would be a cool blog post if you had the time. I've been thinking about really high volume applications that connect to haproxy instances that do DB load balancing but even that has it's own set of initial latency issues. I haven't fully figured out that architecture. In python in particular I'd really love to know how to setup the connection reuse.

Check out the handler source code in Zappa for an example of a pattern like that. Similarly, if you use Zappa to deploy your application, if you create your database connection when the application loads, it'll just work.

Stop by the Zappa slack if you want to explore this in more detail! https://slack.zappa.io It could always use more investigation, but there are quite a few Zappa users at extremely high loads now without any issues.

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#49
post #31

Earlier quoted context omitted.

Some people prefer to call it Function as a Service, which in most cases is closer to what it actually is. "serverless" does not refer to the absolute lack of servers - it refers to the fact that your CODE (applications and software in general) should not be AWARE of being executed on a physical or virtual machine. The platform should be as abstract as it gets. I always imagine it as coding on a piece of paper: in a…

> it refers to the fact that your CODE (applications and software in general) should not be AWARE of being executed on a physical or virtual machine. With the exception of para-virtualised device drivers, what code is ever aware of being executed on physical or virtual machines?

C'mon now, you know what was meant...

Re: Going Serverless: Migrating an Express App to AWS API Gateway and AWS Lambda

#50
post #27
post #11

I love lambda's, but api gateway was far from mature the last time I used it (6 months ago). Unless they have made serious updates to the deployment workflow, feature set, and documentation I would not recommend building your products on it.

I'm in the same boat. I have 4 microscervices set up with API Gateway + Lambda and now actively guide people away from API Gateway.

Do you have any feedback that I can pass along to the team? Post it here or email it to me (email in profile).
Post reply on HN