Condition Functions

You can use intrinsic functions, such as Fn::If, Fn::Equals, and Fn::Not, to conditionally create stack resources. These conditions are evaluated based on input parameters that you declare when you create or update a stack. After you define all your conditions, you can associate them with resources or resource properties in the Resources and Outputs sections of a template.

Lono supports Condition Functions. Since most of these function names are Ruby keywords they must be called with a bang (!).

  • equals
  • and!
  • if!
  • not!
  • or!

Examples follow:

Example: equals

condition("UseProdCondition",
  equals(ref("EnvironmentType"), "prod")
)

outputs:

Conditions:
  UseProdCondition:
    Fn::Equals:
    - Ref: EnvironmentType
    - prod

Example: and!

condition("MyAndCondition",
  and!(equals("sg-mysggroup", ref("ASecurityGroup")), {Condition: "SomeOtherCondition"})
)

outputs:

Conditions:
  MyAndCondition:
    Fn::And:
    - Fn::Equals:
      - sg-mysggroup
      - Ref: ASecurityGroup
    - Condition: SomeOtherCondition

Example: if!

condition("SecurityGroups",
  if!("CreateNewSecurityGroup", ref("NewSecurityGroup"), ref("ExistingSecurityGroup"))
)

outputs:

Conditions:
  SecurityGroups:
    Fn::If:
    - CreateNewSecurityGroup
    - Ref: NewSecurityGroup
    - Ref: ExistingSecurityGroup

Example: not!

condition("MyNotCondition",
  not!(equals(ref("EnvironmentType"), "prod"))
)

outputs:

Conditions:
  MyNotCondition:
    Fn::Not:
    - Fn::Equals:
      - Ref: EnvironmentType
      - prod

Example: or!

condition("MyOrCondition",
  or!(equals("sg-mysggroup", ref("ASecurityGroup")), {Condition: "SomeOtherCondition"})
)

outputs:

Conditions:
  MyOrCondition:
    Fn::Or:
    - Fn::Equals:
      - sg-mysggroup
      - Ref: ASecurityGroup
    - Condition: SomeOtherCondition

Back to Intrinsic Functions List.