Adding more than one security group to AWS lambda Function in template

Viewed 186

I want to add two security group to a lambda function in template. However, it is a conditional statement and i can't find how i can do it. I'm giving an example below:

VpcConfig:
        SecurityGroupIds:
           - !If 
            - isProd
            - !Ref SecurityIds + securityGroup2
            - !Ref SecurityIds

SecurityIds is a security group which is referenced. My aim is that if environment is prod then it should be added two security group to the lambda (SecurityIds + SecurityGroup2) if it is not prod just add one security group (SecurityIds). I don't want to add all lambdas the securityGroup2 because of that i can't add this security group to SecurityIds list.

1 Answers

You were quite close. The way it should be is:

      VpcConfig:
        SecurityGroupIds:
          !If
            - isProd
            - [!Ref SecurityIds, securityGroup2]
            - [!Ref SecurityIds]

Please note all indentations and lack of - before !If.

Related