图片上传后自动生成缩略图
这个更像 Serverless / FaaS 场景:
用户上传图片
↓
API Gateway
↓
Lambda
↓
S3 保存原图
↓
S3 upload event 触发另一个 Lambda
↓
生成缩略图
↓
保存回 S3这个场景里,可能根本不需要你自己配置 EC2、public subnet、private subnet。
因为:
API Gateway 是 AWS 托管服务
Lambda 是 AWS 托管服务
S3 是 AWS 托管服务所以最简单的 Serverless 架构是:
Client
↓
API Gateway
↓
Lambda
↓
S3 / DynamoDB但是如果这个 Lambda 需要访问 private subnet 里的数据库,例如 RDS,那么就变成:
Client
↓
API Gateway
↓
Lambda attached to VPC private subnet
↓
RDS in private subnet如果这个 Lambda 还要访问外部 API,比如调用第三方图片审核服务,那么它可能需要:
Lambda in Private Subnet
↓
Private Route Table
↓
NAT Gateway in Public Subnet
↓
Internet Gateway
↓
External API这时候 VPC、private subnet、NAT Gateway、route table 又都出现了。