I have the following AWS Architecture:
The lambdas can be triggered by API Gateway, SNS, or SQS.
I tried to close as much as possible the IPs and Ports of the Security Groups and ACL of Lambda and RDS Infrastructure.
The SG and NACL of the RDS are very closed, it only allows the Lambda to access it, but the Lambda Security Group and NACL are opening 0.0.0.0/0 Inbound/Outbound.
See the following structure:
- A NAT gateway uses ports 1024-65535.
- AWS Lambda functions use ports 1024-65535.
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html
API Gateway supports the following endpoint ports: 80, 443 and 1024-65535.
https://docs.aws.amazon.com/apigateway/latest/developerguide/setup-http-integrations.html
I used VPC Flow to see what IPs and Ports were entering the Lambda Subnet, and what I could understand that they were dynamic and they keep changing.
I found in many recommendations that you shouldn't use 0.0.0.0/0 and should close as much as possible the IPs and ports, how can I close even more my Security for this architecture?
I also found this link that creates a lambda to dynamically creates the rules-based in the IP list from amazon. Is that the best way to do this?
https://blog.rowanudell.com/updating-security-groups-with-lambda/