Serverless Security: IAM Least Privilege, VPC Networking & Secrets Governance
A shared Lambda execution role with broad policies is the serverless equivalent of running all processes as root — every function in the account inherits the same blast radius. This article covers per-function IAM least privilege, resource-level ARN scoping, condition keys for additional constraints, VPC networking for Lambda (Hyperplane ENI model, no cold-start cost post-2019), VPC Endpoints eliminating NAT Gateway data charges, and Secrets Manager rotation architecture.
AWS Serverless Engineering: Lambda to Production
Serverless Security: IAM Least Privilege, VPC Networking & Secrets Governance
Every AWS primitive is a tradeoff surface, not a feature toggle. The IAM anti-pattern that every AWS security review flags first: a single Lambda execution role attached to every function in the service, with dynamodb:* on * and s3:* on *. The reasoning is understandable — convenience and the assumption that "it's all in the same account anyway." The risk is that IAM permissions are an envelope of impact when credentials are compromised. If every function shares the same role, a single compromised function can read every DynamoDB table, write to every S3 bucket, and invoke every other Lambda in the account. Least privilege is not an audit checkbox — it is blast radius engineering.
1. Per-Function IAM Least Privilege
The correct IAM model for serverless is one role per function, scoped to the exact resources that function accesses.
1.1 Resource-Level ARN Scoping
1.2 Condition Keys — A Second Constraint Layer
Condition keys add additional constraints beyond action + resource. Useful for:
The dynamodb:LeadingKeys condition requires ForAllValues:StringLike (not StringLike) because the request may include multiple partition key values in a BatchGetItem. ForAllValues ensures the condition applies to every key in the batch. Using StringLike alone only evaluates the first key and allows arbitrary keys in batch operations.
2. VPC Networking for Lambda
Lambda can run inside a VPC (for RDS, ElastiCache, or private service access) or outside a VPC (for DynamoDB, S3, SQS, and public internet access). Post-2019, VPC attachment no longer adds cold-start latency — the Hyperplane ENI model pre-allocates ENIs and shares them across Lambda functions in the same VPC/subnet/security group configuration.
2.1 VPC Attachment — When to Use It
| Scenario | VPC needed? | Reasoning |
|---|---|---|
| Lambda → DynamoDB | ❌ | VPC Endpoint routes privately; no need for VPC attachment |
| Lambda → S3 | ❌ | VPC Endpoint routes privately |
| Lambda → RDS/Aurora | ✅ | RDS only accessible inside VPC |
| Lambda → ElastiCache | ✅ | ElastiCache only accessible inside VPC |
| Lambda → public internet | ❌ (NAT) | VPC attachment + NAT Gateway required for outbound internet |
2.2 VPC Endpoints — Eliminating NAT Gateway Data Charges
NAT Gateway charges $0.045 per GB of data processed. VPC Endpoints (Interface Endpoints and Gateway Endpoints) route traffic to AWS services through the AWS backbone network without traversing the public internet.
NAT vs VPC Endpoint cost model:
Add DynamoDB and S3 Gateway Endpoints to every VPC that has Lambda functions accessing these services. They have zero cost, zero configuration overhead, and reduce NAT Gateway data processing charges immediately. This is one of the highest-ROI AWS networking optimizations available.
3. Secrets Management Governance
3.1 Anti-Pattern: Environment Variable Secrets
3.2 Secrets Manager with Lambda Extension Cache
3.3 Automatic Rotation


Summary
| Concept | Rule |
|---|---|
| IAM per-function roles | One role per function, scoped to exact resource ARNs — shared roles = shared blast radius |
| Condition keys | Second constraint layer — dynamodb:LeadingKeys for partition key scoping, aws:SourceVpc for network-bound access |
| VPC for Lambda | Only when function needs RDS, ElastiCache, or private services — not needed for DynamoDB, S3, SQS |
| Gateway VPC Endpoints | Always add for DynamoDB and S3 in VPC Lambdas — free, reduces NAT data charges immediately |
| Secrets in env vars | Anti-pattern — visible in console, CloudTrail, logs; not rotatable without redeployment |
| Secrets Manager + Extension | Caches secrets locally in the Lambda MicroVM; TTL-based refresh; automatic rotation supported |
What's Next
In Part 12: Serverless Observability & FinOps — CloudWatch, X-Ray & Cost Modeling, we turn to the observability layer that makes all prior engineering decisions visible in production: EMF for zero-overhead custom metrics, X-Ray for distributed trace correlation across async fan-outs, and the unit-economics cost models that reveal where DynamoDB Scan or Lambda memory misconfiguration is creating silent billing surprises.
This article was developed with AI-assisted deep search, specification cross-referencing, and technical research synthesis.