brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.11k stars 367 forks source link

Document using RDS (MySQL/PostgreSQL) via a VPC #256

Closed mnapoli closed 5 years ago

mnapoli commented 5 years ago

This is currently not documented and is a major use case of Bref.

Limitations: using MySQL or PostgreSQL from Bref via RDS requires using a VPC. That means:

You are free to comment below with any information that can help regarding this topic. This issue can serve as an alternative to documentation until such a documentation article exists.

atrope commented 5 years ago

@mnapoli Why do you feel that cold starts are arround 5s with VPC? I Read here in many places and in my experience it never happened.

I Am using Lambda PHP With Aurora MySQL in a prod env with more than 1B calls/mo(API and Web). In my use case(with ALBs) our cold starts are never more than 400ms. Usually is less

mnapoli commented 5 years ago

See https://mikhail.io/serverless/coldstarts/aws/ for an up-to-date measurment of cold starts on AWS, specifically the part about VPC. In any case this is something that is documented in all cold start benchmarks that I read online. I also see them myself. You may not be seeing them because of the volume, and maybe because such a volume keeps lambdas warm?

From what I've seen it seems the VPC part of the cold start (the 5s) are not reported in the cloudwatch logs (and in the lambda duration itself). I need to dig more into this.

mnapoli commented 5 years ago

@atrope by the way it would be extremely interesting to learn a bit more about your stack. Have you written an article online about it? We have a Case studies page in the documentation where we could link to it. If you haven't I encourage you to write it ^^

atrope commented 5 years ago

@mnapoli we still need to find time to write something about our experiences in converting our whole structure to serverless :). As soon as we do, I Will be sure to ping you.

As for the cold start part.. it could be our volume that we don't ever notice it, but even in our tests envs we dont see that much time.

Also we use ALBs healthchecks to keep them warm.

Now i will stop hijacking this issue!

mnapoli commented 5 years ago

@atrope can't wait to read about your project!

And regarding this issue I might be able to publish some documentation this week! (I'll try to spend 1 or 2 days on Bref this week)

viezel commented 5 years ago

@mnapoli could you quickly share some insights into getting VPC working as this issue is addressing this? Im still struggling with this getting timeouts and 500 errors.

mnapoli commented 5 years ago

@viezel please read the pull request (#269).

viezel commented 5 years ago

I did, and I configured it as well:

Policies:
   - VPCAccessPolicy: {}
   - AWSLambdaVPCAccessExecutionRole
VpcConfig:
   SecurityGroupIds:
      - 'sg-xxx'
   SubnetIds:
      - 'subnet-aaa'
      - 'subnet-bbb'
      - 'subnet-ccc'

but app says:

Fatal error: Uncaught Hoa\Socket\Exception\Exception: Client returns an error (number 111): Connection refused while trying to join unix:///tmp/.bref/php-fpm.sock. in /var/task/vendor/hoa/socket/Client.php:19