如何根据环境在云的形成中给出单独的变量

How to give separate variables in cloud formation with respect to environment

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)

您可以使用 If:

      VpcConfig:
        SecurityGroupIds:
          - !If [IsEnvStage, !Ref SG1, !Ref SG2]