是否可以创建一个无服务器框架Lambda部署,使Lambda部署到现有VPC的安全组中?我不想让服务部署或其堆栈拥有任何网络构件。
是否可以创建一个无服务器框架Lambda部署,使Lambda部署到现有VPC的安全组中?我不想让服务部署或其堆栈拥有任何网络构件。
是的,可以。在serverless.yml
中,vpc
配置只需要引用现有的子网和安全组即可。例如:
vpc:
securityGroupIds:
- securityGroupId1
- securityGroupId2
subnetIds:
- subnetId1
- subnetId2
sls deploy --force
命令,甚至需要删除并重新部署无服务器 API。 - Derropsprovider:
name: aws
....
....
vpc:
securityGroupIds:
- ${self:custom.securityGroupId.${self:provider.stage}}
subnetIds:
- ${self:custom.subnetId.${self:provider.stage}}
custom:
stages:
- tst
- dev
- prd
securityGroupId:
local: sg-local
tst: sg-tst
dev: sg-dev
prd: sg-prd
subnetId:
local: subnet-local
tst: subnet-tst
dev: subnet-dev
prd: subnet-prd
plugins:
- serverless-stage-manager
@Nebulastic提供的答案有所补充。
当您希望配置VPC Lambda以从多个子网执行不同阶段时,就可以使用此方法。
provider:
name: aws
vpc:
securityGroupIds:
- ${self:custom.securityGroupId.${self:provider.stage}}
subnetIds:
- ${self:custom.subnetId1.${self:provider.stage}}
- ${self:custom.subnetId2.${self:provider.stage}}
- ${self:custom.subnetId3.${self:provider.stage}}
custom:
stage: ${opt:stage, self:provider.stage}
securityGroupId:
prod: sgId-prod
test: sgId-test
dev: sgId-dev
subnetId1:
prod: subnetId1-prod
test: subnetId1-test
dev: subnetId1-dev
subnetId2:
prod: subnetId2-prod
test: subnetId2-test
dev: subnetId2-dev
subnetId2:
prod: subnetId3-prod
test: subnetId3-test
dev: subnetId3-dev