Serverless functions don’t remove your network attack surface – they move it, and often in ways that make your remaining servers more exposed than before. If you run workloads on AWS Lambda, Azure Functions or Google Cloud Run functions, understanding serverless functions and their network boundaries tells you where an attacker can actually reach your code, and which of your traditional hosts quietly got riskier during the migration. This article covers inbound and outbound boundaries, the VPC trap that leaves databases open, and how to check your real exposure from the outside.
Where Serverless Network Boundaries Actually Sit
A Lambda function has no public IP address of its own and no listening socket you control. Requests reach it through an AWS front door: API Gateway, an Application Load Balancer, a Lambda function URL or an event source like SQS. The same holds for Azure Functions behind the App Service front end and for Cloud Run functions behind Google’s front end.
So the inbound boundary is not a port. It is a combination of endpoint configuration and identity policy. A Lambda function URL with AuthType set to NONE is reachable by anyone on the internet over HTTPS on 443, with no firewall rule involved. A Cloud Run function with the allUsers principal granted the invoker role is just as public. Neither one shows up as an open port on any server you own.
The outbound boundary matters more. By default, a Lambda function not attached to a VPC has unrestricted internet egress through AWS-managed networking. It can call any host on any port, and you cannot attach a security group to restrict it. In practice this is where data exfiltration happens after a dependency compromise or a code injection bug.
The Myth That Serverless Has Nothing to Scan
A common belief: “We went serverless, so there are no open ports to worry about.” That’s only half right. Scanning API Gateway or *.azurewebsites.net addresses tells you nothing useful. Those are shared provider front ends, and scanning them is outside most providers’ acceptable use terms anyway.
The real exposure comes from what the functions need to reach. Functions talk to databases, caches, message brokers and legacy APIs, and those still live on hosts with real ports. When a team can’t get a function to connect to something, the quickest fix is almost always to loosen a network boundary somewhere else.
A Familiar Migration Scenario
A team moves a monolith’s REST API to Lambda over a 6-8 week sprint. The PostgreSQL instance stays on RDS in a private subnet. The first deployment fails: the functions, running outside the VPC, time out connecting to the database.
Attaching Lambda to the VPC would fix it. Then the functions lose internet access for third-party API calls unless someone adds a NAT gateway, which runs about $0.045 per hour plus $0.045 per GB processed in us-east-1. Nobody wants to open a budget conversation on deadline day. So someone flips RDS to “publicly accessible” and adds an inbound rule allowing 5432 from 0.0.0.0/0, because Lambda egress IPs are unpredictable and there’s nothing narrower to allowlist.
The serverless API launches fine. Six months later an external scan turns up PostgreSQL 13 answering on a public IP, accepting password authentication, with the security group description still reading “temp – lambda testing”. This is the pattern serverless adoption produces most often: the functions are safe and the database pays the price.
Common Mistakes Practitioners Make
The first mistake is widening a data-tier security group to 0.0.0.0/0 to accommodate functions, as in the scenario above. The same thing happens with Redis on 6379, MongoDB on 27017 and Elasticsearch on 9200. The correct fix is VPC attachment, where Lambda uses Hyperplane ENIs that carry a security group. The database rule then references that security group ID instead of a CIDR range.
The second is assuming VPC attachment equals lockdown. The default security group for a VPC-attached function allows all outbound traffic. If the subnet routes through a NAT gateway, the function still has full internet egress, just from a predictable IP. An experienced cloud security engineer restricts outbound rules to the specific ports and destinations the function needs and uses VPC endpoints for S3, DynamoDB and Secrets Manager so that traffic never leaves the AWS network.
The third is forgetting the side doors. On Azure Functions, the Kudu/SCM site at *.scm.azurewebsites.net stays publicly reachable unless access restrictions are set on it separately from the main site. Debug function URLs created during development often survive into production, and so do Cloud Run services deployed with “allow unauthenticated” during testing.
Hardening Steps That Hold Up
A seasoned cloud security lead usually works through serverless exposure in this order:
1. Inventory every invocation path: function URLs, API Gateway stages, ALB targets and public HTTP triggers, including their auth settings.
2. Attach functions that touch private data stores to a VPC and reference their security group, not CIDR blocks, in database rules.
3. Restrict function egress to known destinations and add VPC endpoints for cloud-native services.
4. Run an external scan against every public IP in the account, especially Elastic IPs and RDS endpoints, to confirm nothing on the data tier is still reachable.
5. Re-check after every infrastructure-as-code change that touches security groups or “publicly accessible” flags.
Step 4 is the one teams skip. Cloud consoles show what is configured. An external scan shows what is actually reachable, and the two drift apart over time. The AWS, Azure and GCP port security guide covers the provider-specific controls in more depth.
Edge Cases Where Standard Advice Breaks
Not every function can live in a VPC. Lambda@Edge and CloudFront Functions run at edge locations with no VPC attachment option, so the backends they call must be reachable over the internet. Here the protection has to come from origin authentication, such as a secret header or signed requests, and an origin firewall limited to CloudFront’s managed prefix list.
Self-hosted serverless platforms change things completely. OpenFaaS exposes its gateway on port 8080 by default, and Knative depends on an ingress layer like Kourier or Istio. In those setups you own real listening ports, NodePorts and admin interfaces, and the classic port scanning discipline applies in full. Air-gapped and on-prem regulated environments usually end up here.
Under PCI DSS 4.0, a function that handles cardholder data brings its connected network segments into scope. If a Lambda reaches a database that is also internet-reachable, an assessor will flag the database, not the function. Teams under 10 people with a handful of functions can often skip VPC attachment entirely, as long as their data stores are managed services with IAM-based authentication, like DynamoDB, rather than port-based databases.
FAQ: Serverless Exposure Questions
Can I port scan my Lambda functions directly?
No. Functions sit behind shared provider infrastructure, and scanning those addresses tells you nothing about your configuration. Scan the public IPs you own instead, such as Elastic IPs, NAT gateways, load balancers and database endpoints, and audit function invocation settings through the provider API.
Does putting a Lambda in a VPC make it more secure?
Only if you configure it. VPC attachment lets you use security groups and private routing, but the default outbound rule allows everything. The real benefit is that your databases can stay private.
How do I find serverless-related exposure I don’t know about?
Compare current security group rules against your infrastructure-as-code definitions, then run an external scan of all your public IPs. Any data-tier port that answers from the internet should be traced back to the change that opened it. That is often a function deployment.
Final Takeaway on Serverless Boundaries
Serverless moves the inbound boundary from ports to identity and endpoint configuration, and it pushes network risk onto the systems your functions depend on. Audit auth settings on every trigger, keep data stores private with security group references, and restrict egress. Then verify the result from the outside, because the database someone opened “temporarily” for a function is exactly what attackers find first. For broader context, see this guide to understanding your attack surface.
