在 Cloudformation 中为 Lambda 代码使用字符串函数

Using string functions in Cloudformation for Lambda Code

我有一个大致如下所示的 cloudformation 片段:

"LambdaScale": {
  "Type": "AWS::Lambda::Function",
  "Properties": {
    ...
    "Code": {
      "S3Bucket": {
        {
          "Ref": "LambdaBucket"
        }
      },
      "S3Key": {
        "Fn::Join": [
          "/",
          [
            { 
              "Ref": "LambdaDirectoryKey"
            },
            "some_func.zip"
          ]
        ]
      }
    },
 ...
 }

但是当我尝试 运行 时,出现以下错误:

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: [/Resources/LambdaScale/Type/Code/S3Bucket] map keys must be strings; received a map instead

读到这里,我觉得 S3Bucket 和 S3Key 属性需要一个字符串文字,并且不支持字符串操作函数。这真的是真的吗?如果是这样,那将是在不同环境中部署这些模板的巨大障碍。

是否有我没有考虑过的解决方法?感谢您的任何建议!

你有:

  "S3Bucket": {
    {
      "Ref": "LambdaBucket"
    }
  },

大概应该是:

  "S3Bucket": {
      "Ref": "LambdaBucket"
  },