[AWS] Optional (null) list item in Cloud Formation template with
TL;TR
Use AWS::NoValue
as NULL
value.
The problem
I want to create a CloudFormation template on AWS which some optional setting. This should be controlled over a parameter.
Let’s say we have a CloudFront Distribution which get should pre validated from a Lambda. This looks like this snippet of code:
Here is missing a variable option to enable/disable the authentication lambda.
Solution
We need somthing like an if-function and this function is supported by CloudFormation. AWS give us some functions in YAML or JSON to make dynamic templates.
We want to use Fn::If
. The next part is that this function only allow two parameters to say A
or B
. But we don’t want a B
value. To solve this we can use AWS::NoValue
.
So we need to extend our template like this:
That’s it!
References
- Condition Functions
- Pseudo Parameters Reference
- How to make a list item conditional in Cloud Formation template?
Contact
If you have questions or corrections contact me at info@liveyourproject.com.
Author: Fabian Keunecke