Skip to main content
Marcel Krčah

Defining resources conditionally based on environment

Published on , in , ,

Here's an example that defines input for a scheduled Lambda event based on environment, using Conditions and Condition Functions.

Two important things:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
  Environment:
    Type: String
    AllowedValues:
      - acc
      - prod

Conditions: # <-- define conditions here
  IsProd: !Equals
    - !Ref Environment
    - prod

Resources:
  Main:
    Type: AWS::Serverless::Function
	Events:
	  PeriodicTrigger:
		Type: Schedule
		Properties:
		  Schedule: rate(5 minutes)
		  Input: !If [ IsProd, '"foo"', '"bar"' ]  #  🎉
	# ... CodeUri, etc...

This blog is written by Marcel Krcah, an independent consultant for product-oriented software engineering. If you like what you read, sign up for my newsletter