Development with AWS Services

A Lambda function attached to a public subnet can reach a private database but times out when calling a public HTTPS API. The subnet routes internet traffic to an internet gateway; what change restores API access while preserving private database access?

Show the answer

Correct answerC. Use private subnets with an internet route through a public NAT gateway.

AWhy not this: Lambda-managed network interfaces do not support assigning an Elastic IP address directly.

BWhy not this: Inbound HTTPS rules do not provide a route for outbound API requests.

CWhy this is right: A public NAT gateway supplies outbound internet connectivity while the function retains private VPC connectivity.

DWhy not this: A longer timeout cannot establish an outbound internet path that the network configuration lacks.

VPC-connected Lambda functions do not receive public IP addresses, so an internet gateway route alone does not provide internet access. Private subnets routing through a public NAT gateway provide outbound access; increasing the timeout does not fix missing connectivity.