CloudFormation - 参考资源作为参数的默认值

CloudFormation - reference resource as default value for Parameter

我有一个参数 "SecretKey",我想为其提供一个默认值(http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html) and the default value would be a generated random string. I already have a lambda function 来生成密钥和自定义资源(称之为 RandomSecretKey)获取值。最终,我希望能够在参数部分执行此操作:

"SecretKey":{<br> ... "Default": { "Fn::GetAtt": ["RandomSecretKey", "Value"] } }

而且这个参数会在某处被引用。

但这不起作用,因为 CloudFormation 需要基于错误消息的静态字符串。有办法吗?

没有。 CloudFormation 不可能有动态默认值。原因是收集参数时模板还没有执行。

如果您希望它成为参数,则您生成的值必须在模板外部生成并作为参数传递到模板中。您可以通过引导创建脚本执行此操作。

或者,您应该能够在模板中使用自定义资源来生成随机密钥。它应该能够通过堆栈更新持续存在。

参考文献: