SAM模板环境变量使用map、list、关联数组?

SAM template environment variables use map, list, associative array?

我只在 SAM 模板中看到过具有单个值的示例:

Environment:
  Variables:
    TABLE_NAME: my-table

我想做这样的事情,但似乎行不通:

Environment:
  Variables:
      myVar:
      -   prop1: aaa
          prop2: sdfsdfsd
          prop3: ssss
      -   prop1: bbb
          prop2: wwwwww
          prop3: aaaaa

我想要一个类似于对象列表的环境变量。我可以存储一个带分隔符的字符串并自己解析它,但我更希望它像 object/map/list 一样,就像我准备好一个 YAML 文件一样。

最接近的做法是 json 对环境变量的值进行编码 并使用运行时语言对其进行解码:

 Environment:
  Variables:
    USER: '{"name": "john", "surname": "galt"}'

如果您想阻止对每个请求进行解码 json,请将您的解码逻辑移到处理程序之外,在这种情况下,当 lambda 处于热状态时代码将不会重新执行。

Any declarations in your Lambda function code (outside the handler code, see Programming Model) remains initialized, providing additional optimization when the function is invoked again. For example, if your Lambda function establishes a database connection, instead of reestablishing the connection, the original connection is used in subsequent invocations. We suggest adding logic in your code to check if a connection exists before creating one.

了解 lambda execution model

我个人会创建一个 json 文件,将其存储在 s3 存储桶中并使用环境变量为该文件指定 s3 url。此外,根据检索 config 文件

时的情况,使用我上面提到的相同技术或使用更复杂的缓存机制