NAT Gateway e accesso a Internet da una VPC
Scopra perché una Lambda all’interno di una subnet privata VPC perde l’accesso a Internet e come i NAT gateway e gli endpoint VPC ripristinino la connettività in sicurezza.
NAT Gateway e accesso a Internet da una VPC è una lezione Serverless AWS Lambda Development gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Serverless AWS Lambda Development, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Serverless AWS Lambda Development include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
The Surprise
A Lambda in a VPC can reach private resources, but it loses default internet access. Calls to public APIs suddenly time out.
Why It Happens
VPC Lambdas have no public IP. Without a route to the internet, outbound calls to external endpoints have nowhere to go.
Public vs Private Subnets
A public subnet routes to an Internet Gateway; a private subnet does not. Always place Lambdas in private subnets for security.
Enter the NAT Gateway
A NAT gateway lives in a public subnet and lets private subnets make outbound internet calls while staying unreachable from the internet.
The Route Table
The private subnet route table sends internet-bound traffic to the NAT gateway, which forwards it through the Internet Gateway.
Destination Target
10.0.0.0/16 local
0.0.0.0/0 nat-0abc123NAT Costs Money
NAT gateways charge per hour plus per GB processed. For heavy traffic this adds up, so consider whether you truly need public internet access.
VPC Endpoints Instead
To reach AWS services like S3 or DynamoDB, use a VPC endpoint. Traffic stays on the AWS network with no NAT needed and no per-GB internet cost.
Gateway vs Interface Endpoints
S3 and DynamoDB use free gateway endpoints; most other services use interface endpoints (powered by PrivateLink) which are billed hourly.
Calling S3 Through an Endpoint
No code change is needed. With a gateway endpoint and the right route, this S3 call never leaves the AWS backbone.
import boto3
s3 = boto3.client('s3')
s3.put_object(Bucket='my-bucket', Key='log.txt', Body=b'hi')Choosing the Right Path
Need a public third-party API? Use a NAT gateway. Need only AWS services? Use VPC endpoints. Often you use endpoints to avoid NAT entirely.
Multi-AZ for Resilience
Deploy a NAT gateway per Availability Zone and put the Lambda in multiple subnets, so one AZ outage does not break connectivity.
Quick Check
Test your VPC networking knowledge.
Recap
You learned why VPC Lambdas lose internet access and how NAT gateways restore outbound access, while VPC endpoints reach AWS services privately and cheaply.
Domande Frequenti
La lezione «NAT Gateway e accesso a Internet da una VPC» è gratuita?
Sì — il testo completo di «NAT Gateway e accesso a Internet da una VPC» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Serverless AWS Lambda Development, passa a CoddyKit PRO. Il corso Serverless AWS Lambda Development include 4 lezioni in totale.
Cosa imparerò in «NAT Gateway e accesso a Internet da una VPC»?
Scopra perché una Lambda all’interno di una subnet privata VPC perde l’accesso a Internet e come i NAT gateway e gli endpoint VPC ripristinino la connettività in sicurezza. Eserciti Serverless AWS Lambda Development con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Serverless AWS Lambda Development?
Non è richiesta alcuna esperienza precedente. Serverless AWS Lambda Development su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «NAT Gateway e accesso a Internet da una VPC»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Serverless AWS Lambda Development?
Sì. Ogni lezione Serverless AWS Lambda Development include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Lambda in una VPC per risorse private
- Accesso ai database in una VPC
- Best practice per la sicurezza di rete
- NAT Gateway e accesso a Internet da una VPC