- I have 2 different security groups in stage and prod
- For lambda function I have to give SG1 if its stage and SG2 if its prod
- Do i need to write separate resources in template or I can given any conditional expressions
- My security group SG1 and SG2 is deployed from this template only
Conditions:
IsEnvProd: Fn::Equals [ !Ref Env, 'prod' ]
IsEnvStage: Fn::Equals [ !Ref Env, 'stage' ]
BackupLambda:
Type: "AWS::Lambda::Function"
Properties:
Handler: "backup_lambda.lambda_handler"
Role: !Ref Role
Runtime: "python2.7"
MemorySize: 128
Timeout: 120
Code:
S3Bucket: !Ref BucketWithLambdaFunction
S3Key: !Ref PathToLambdaFile
VpcConfig:
SecurityGroupIds:
- !Ref SG1 # if its stage(IsEnvStage)
- !Ref SG2 # if its prod(IsEnvProd)
CodePudding user response:
You can use If:
VpcConfig:
SecurityGroupIds:
- !If [IsEnvStage, !Ref SG1, !Ref SG2]