阅读背景:

Cloudformation模板格式错误:每个DeletionPolicy成员必须是一个字符串

来源:互联网 

Hi I am trying to use the "IF" Function just like mentioned in cloud formation documentation for RDS DeletionPolicy, but for some reason it says that my function does not return a string.

嗨,我正在尝试使用“IF”函数,就像在RDS DeletionPolicy的云形成文档中提到的那样,但由于某种原因,它说我的函数不返回字符串。

AWS Documentation on conditional statements

关于条件语句的AWS文档

here is the condition:

这是条件:

"DeletionPolicy" : {
    "Fn::If" : [
      "CreateProdResources",
      "Snapshot",
      "Delete"
    ]}

And the error is the one in the title:

错误是标题中的错误:

Template validation error: Template format error: Every DeletionPolicy member must be a string.

Other attempts that didn't work:

其他尝试不起作用:

With a map:

有了地图:

"RdsDeletionPolicyMap" :{
      "production" : {
          "policy" : "Snapshot"
      },
      "staging" : {
          "policy" : "Delete"
      }
   }

And then:

接着:

  "DeletionPolicy" : {
      "Fn::FindInMap" : [ "RdsDeletionPolicyMap", {"Ref": "RailsEnvironment"}, "policy" ]
   }

As well as a Simple "Ref": ... didn't work as well. I highly suspect this is a bug with cloudformation

除了简单的“参考”:......也不行。我非常怀疑这是一个关于cloudformation的错误

1 个解决方案

#1


7  

The issue is that DeletionPolicy must be set to one of three strings. And, though your If check will return one of them, from a systematic perspective, it only knows that it's returning a String - but is not guaranteed to be a valid string (same with your map and parameter checks), and thus it only accepts a string literal and not something that resolves to string.

问题是DeletionPolicy必须设置为三个字符串之一。并且,虽然你的If检查将返回其中一个,从系统的角度来看,它只知道它返回一个String - 但不保证是一个有效的字符串(与你的map和参数检查相同),因此它只接受字符串文字,而不是解析为字符串的东西。

I believe that this limitation has been raised to the AWS Engineering team previously, as it is a nuisance.

我认为此限制已经提交给AWS工程团队,因为这是一个令人讨厌的问题。


分享到: