AWS Lambda | API Gateway | VPC | RDS | NodeJS | TypeORM
Problem Statement
Timeout issue when a user connects RDS MySQL (NodeJS — TypeORM) via Lambda + API Gateway.
Solution:
Let's create your VPC network as shown below.
Step 1: Create an AWS API gateway
Step 2: Create a Lambda function & include trigger API gateway
Step 3: Attach the policy to grant access your VPC network via AWS Lambda
Step 4: Provide access to VPC & subnets via security groups (Enable RDS MySQL port — 3306)
Step 5: Serverless coding access the rds database via TypeORM
Now we can trigger and check the API.
Source code:
https://github.com/anniyanvr/medium/tree/master/typeorm-awslambda
References:
https://docs.aws.amazon.com/lambda/latest/dg/services-rds-tutorial.html
https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html