- Newest
- Most votes
- Most comments
Another option that might work (I haven't tried it myself) if the other suggestions aren't possible for some reason is to put the Lambda in a public subnet and attach an Elastic IP to its ENI. Since the VPC Lambda networking improvements of 2019/20 the ENIs are long-lived but still AWS do not recommend doing this because the ENI could be deleted if unused for weeks, and could be supplemented by additional ENIs if there's high concurrency. This approach maybe could work if set up carefully.
When you place a Lambda function in a VPC to access resources like ElastiCache Serverless, you're correct that the function loses direct internet access and can't reach AWS services outside the VPC by default.
For accessing AWS services without using a NAT Gateway, AWS PrivateLink with interface VPC endpoints is the recommended approach. This allows your Lambda function to privately access AWS services without traversing the public internet.
You can create interface VPC endpoints for most of the services you mentioned:
- API Gateway
- Cognito
- Parameter Store (Systems Manager)
However, you're correct that CloudFront doesn't currently support VPC endpoints. For this specific service, you have limited options:
- Use a NAT Gateway (which you want to avoid)
- Consider an IPv6 approach - Lambda functions can make IPv6 outbound connections, and you could use an Egress-only Internet Gateway instead of a NAT Gateway
- Restructure your application to handle CloudFront interactions from components that aren't in the VPC
Using VPC endpoints for the supported services will help minimize your dependency on internet access. Interface endpoints are powered by AWS PrivateLink and are generally more cost-effective than NAT Gateways while providing secure private connectivity between your VPC and AWS services.
For your specific architecture, you could implement VPC endpoints for API Gateway, Cognito, and Parameter Store, then evaluate whether you can restructure the CloudFront interactions or if you'll need to use one of the alternative approaches for that specific service.
Sources
Leverage VPC endpoints - Serverless Applications Lens
Lambda in RDS VPC needs bi-directional inet access | AWS re:Post
Configure Lambda without NAT for trigger API Gateway and use DocumentDB | AWS re:Post
Connect your VPC to services using AWS PrivateLink - Amazon Virtual Private Cloud
Yes, you can create Interface VPC Endpoints (AWS PrivateLink) for most of the services you mentioned, including:
Amazon API Gateway (for private APIs)
AWS Cognito
AWS Systems Manager Parameter Store
These services support interface endpoints, allowing secure, private connectivity over the AWS network without using the public internet.
Regarding CloudFront: CloudFront does not support VPC endpoints directly because it's a global edge service that acts as a content delivery layer in front of your origin (e.g., ALB or S3).
However, if your CloudFront origin is:
An Application Load Balancer (ALB) within a VPC
Or an S3 bucket (with static website hosting disabled)
You can:
Expose the origin using an Interface VPC Endpoint (PrivateLink)
Set up a private DNS name using Route 53 that resolves to the VPC endpoint
Configure CloudFront with a custom origin domain name that routes through the PrivateLink
This ensures that CloudFront communicates privately with your internal origin resources without traversing the internet.
Relevant content
- asked 8 months ago
- AWS OFFICIALUpdated 5 years ago
- AWS OFFICIALUpdated 2 years ago

Good idea Steve, afraid this is not supported. Lambda will not obtain a public IP in a public subnet. It has to reside in a Private subnet with either Endpoints and or NAT Gateways
@Gary Mclean this does work, I tried it just now. You're correct that Lambda will not by default obtain a public IP in a public subnet, but as I said you have to attach an Elastic IP to its ENI yourself. Once you do this, you now have internet access for the lifetime of the ENI which is largely out of your control but can be influenced by periodically triggering the function. As above "This approach maybe could work if set up carefully" - no guarantees! :)