This is a sample implementation which shows an example of how to setup a serverless project which allows your lambda(s) to connect to both an RDS instance from within a VPC as well as connecting out to the internet. If you don't have much experience working with configuring VPCs or networking rules this will should provide a boilerplate example to get you started with (and is a product of my own initial journey trying to understand and set this up myself).
There is only a small collection of literature about why this is tricky to do and also why you need to do it at all. I won't repeat what's already been written, but it's worth having a read through of some of these resources:
- Accessing VPC Resources With Lambda
- The Dark Art of VPC Networking
- Enabling Outbout Internet Access Within a VPC
- Configure Lambdas to Access an RDS Instance Within a VPC
- How to set up Lambda to talk to the Internet and a VPC
This snippet also borrows heavily from other example configs and setups provided by other developers out there. This setup borrows heavily from:
- https://github.com/ittus/aws-lambda-vpc-nat-examples
- https://github.com/ikim23/aws-lambda-static-ip
- https://github.com/mugglmenzel/serverless-examples-cached-rds-ws
npm install
sls deploy
The