If I create an inbound rule to my RDS that’s open to the internet then my Lambda works but obviously I don’t want to do that. It would be great if I could lock it down to just the ip of the Lambda.
What are you actually trying to do? You want a Lambda to interact with an RDS securely? That’s pretty straightforward. Both of them should go in the same VPC and use IAM roles to control access.
Lambda does not have a static IP when not in a VPC. You could use the entire EC2 range, that’s as limited as you can go. So your function really should go in a VPC. Or if it needs to do things over the internet and with RDS, you could break it up into two functions, and have one function call the other with one in a VPC and one not.
Yeah, as others have mentioned, there isn’t many straight-forward options. A Lambda in a VPC can’t access the internet without a NAT gateway (or something similar), so you’d have to around that. Breaking up the Lambda into one which exists in the VPC and one which exists outside of it is an option, but cumbersome.
If you’re using Aurora, you can enable the Data API to be able to access your database through an HTTP endpoint. Sometimes that’s acceptable and sometimes it’s not, but it works well with Lambdas.
I’ll echo others comments with breaking up the logic if possible, having one Lambda accept data from the internet and pass it to the other Lambda - SQS is often used as an intermediary here.
I’ll also suggest if you do end up determining you need to use NAT, this is a more cost-sensitive approach:
In VPC mode, the RDS inbound rule can reference the Lambda security group. That would limit it to just the related lambda hyperplane ENI, no need for the whole VPC CIDR.
It takes less than 10 minutes to see attacks on ports open to 0.0.0.0, so obviously don’t do that, as you already said.
Using a Lambda and plain vanilla RDS is not a great idea, as lambdas scale horizontally and can spam the available ports in no time. Especially of the Lambda is publicly accessible. Dynamo can take it, RDS is another story entirely.
RDS Proxy pricing correlates to the number of vCPUs of the underlying database instance for which it is enabled. For example, if you are running a single-AZ or multi-AZ RDS MySQL m5.large database instance that has 2 vCPUs and you have enabled the proxy, you will be charged $0.030 per hour for the proxy ($0.015 per vCPU-hour x 2 vCPUs). For a 30-day month your bill would show 1,440 vCPU-hours (2 vCPU x 24 hours x 30 days): $21.60
Otherwise, if you want no additional cost, deploy the lambda in a VPC and put the DB in the private subnet with routes set up accordingly.