More info here: https://coderecipe.ai/architectures/77374273
Problem Statement:
Traditionally, in order to have lambda talking to RDS one would have to introduce a VPC in between, this is problematic because:
-
VPC cold start time takes seconds!
-
Complexity of setting up and maintaining a VPC is really unnecessary
-
VPC is not free either!
Solution:
Using the new Data API provided by AWS Aurora (currently still in beta), an AWS Lambda can directly communicate with the RDS Instance. The Lambda is then connected to an API Gateway to allow user interface.
Functional Requirements:
Be able to query an RDS instance from within a AWS Lambda function without the use of VPC.
Performance Requirements:
Avoid performance issues caused by VPC configuration.
Recipes built on top of this recipe:
How I Build a Scalable Crypto Exchange with AWS and web3.js
Note:
One note about using the Data API is that the sql query being sent over is taken in as raw input and could potentially introduce SQL injection vulnerability. To avoid this, we have sanitized the inputs using mysql.escape.
npm install serverless-python-requirements npm install serverless-pseudo-parameters npm install serverless-iam-roles-per-function npm install serverless-plugin-scripts
pip install -r requirements.txt
serverless deploy --stage <stage_name> --dbUser <db_user>
sls invoke -f AuroraCRUD -d '{"body":{"eventType":"createTable"}}' -l --stage <stage_name> --dbUser <db_user>