in lib/presence-stack.ts [78:98]
private addFunction(name: string, useRedis: boolean = true) : void {
const props = useRedis ? {
vpc: this.vpc,
vpcSubnets: this.vpc.selectSubnets({subnetGroupName: "Lambda"}),
securityGroups: [this.lambdaSG]
} : {};
const fn = new Lambda.Function(this, name, {
...props,
code: Lambda.Code.fromAsset(path.resolve(__dirname, `../src/functions/${name}/`)),
runtime: Lambda.Runtime.NODEJS_12_X,
handler: `${name}.handler`
});
// Specific elements to add for redis access
if (useRedis) {
fn.addLayers(this.redisLayer);
fn.addEnvironment("REDIS_HOST", this.redisCluster.attrPrimaryEndPointAddress);
fn.addEnvironment("REDIS_PORT", this.redisCluster.attrPrimaryEndPointPort);
}
// Store the function for further internal access
this.functions[name] = fn;
};