我有一个 env.yml
文件,在这里我存储了一些变量,这些变量应该被发送给 serverless.yml
. 我想把这个变量数组从 env.yml
至 serverless.yml
.
这是我在 env.yml
securityGroupIds:[sg-xxx]
subnetIds: [subnet-xx1, subnet-xx2, subnet-xx3, subnet-xx4]
这是我在 serverless.yml
:
vpc:
securityGroupIds: ${file(env.yml):securityGroupIds}
subnetIds: ${file(env.yml):securityGroupIds}
这就是我所期待的里面的东西。serverless.yml
当我 sls print --stage dev
:
vpc:
securityGroupIds:
- sg-xxx
subnetIds:
- subnet-xx1
- subnet-xx2
- subnet-xx3
- subnet-xx4
它不工作。我到底做错了什么?
我已经找到了方法。
在... env.yml
:
vpc-dev: {
"securityGroupIds": [
"sg-xxx"
],
"subnetIds": [
"subnet-xx1",
"subnet-xx2",
"subnet-xx3",
"subnet-xx4"
]
}
vpc-prod: {
"securityGroupIds": [
"sg-xxxy"
],
"subnetIds": [
"subnet-xx1y",
"subnet-xx2y",
"subnet-xx3y",
"subnet-xx4y"
]
}
在serverless.yml中
function
hello: ...
handler: ...
...
vpc: ${file(env.yml):vpc-${self:provider.stage}}