如何从env.yml中发送一个变量数组到serverless.yml?

问题描述 投票:1回答:1

我有一个 env.yml 文件,在这里我存储了一些变量,这些变量应该被发送给 serverless.yml. 我想把这个变量数组从 env.ymlserverless.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

它不工作。我到底做错了什么?

arrays yaml serverless-framework
1个回答
0
投票

我已经找到了方法。

在... 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}}
© www.soinside.com 2019 - 2024. All rights reserved.