I want to create an Elastic Beanstalk using CloudFormation template. I want to define an environment variable ENV_VAR_1
and set it's value to value of template parameter var1
. But don't want ENV_VAR_1
to exist at all if var1
is an empty string. I.e. I don't want ENV_VAR_1
with no value.
First I tried the Conditions
, but I get "Encountered unsupported property Condition"
during creation of ElasticBeanstalkEnvironment
resource.
Parameters:
var1:
Type: String
Conditions:
isVar1Empty: !Equals [ !Ref var1, "" ]
Resources:
ElasticBeanstalkEnvironment:
Type: 'AWS::ElasticBeanstalk::Environment'
Properties:
OptionSettings:
- Namespace: 'aws:elasticbeanstalk:application:environment'
Condition: isVar1Empty
OptionName: ENV_VAR_1
Value: !Ref var1
Then I tried AWS::NoValue
Parameters:
var1:
Type: String
Resources:
ElasticBeanstalkEnvironment:
Type: 'AWS::ElasticBeanstalk::Environment'
Properties:
OptionSettings:
- Namespace: 'aws:elasticbeanstalk:application:environment'
OptionName: ENV_VAR_1
Value: !If [[!Equals [ !Ref var1, "" ]], !Ref 'AWS::NoValue', !Ref var1]
and many permutation combinations of this. With the same result: When var1
is empty, Elastic Beanstalk gets created with ENV_VAR_1
set to ""