private initInfra()

in cdk/lib/cdk-stack.ts [147:185]


  private initInfra() {
    const vpc = new ec2.Vpc(this, "SpApiVpc", {
      cidr: '10.233.0.0/16',
      natGateways: 1,
      subnetConfiguration: [{
        cidrMask: 22,
        name: 'private',
        subnetType: ec2.SubnetType.PRIVATE
      }, {
        cidrMask: 22,
        name: 'public',
        subnetType: ec2.SubnetType.PUBLIC
      }]
    });



    const lambdaSG = new ec2.SecurityGroup(this, "SpApiLambdaSG", {
      vpc,
    });

    const redisSG = new ec2.SecurityGroup(this, "SpApiRedisSG", {
      vpc,
      allowAllOutbound: false,
    });
    const redisSubnetGroup = new elasticache.CfnSubnetGroup(this, "SpApiRedisSubnetGroup", {
      description: 'Subnet group of redis cluster',
      subnetIds: vpc.privateSubnets.map((subnet) => subnet.subnetId)
    });
    const redisCluster = new elasticache.CfnCacheCluster(this, "SpApiRedisCluster", {
      cacheNodeType: "cache.t3.micro",
      engine: "redis",
      numCacheNodes: 1,
      cacheSubnetGroupName: redisSubnetGroup.ref,
      vpcSecurityGroupIds: [redisSG.securityGroupId]
    });
    redisSG.addIngressRule(lambdaSG, ec2.Port.tcp(6379), 'Allow access from lambda function');
    return { lambdaSG, vpc, redisCluster };
  }