Przemysław Woźniak
03/15/2022, 10:02 PMFrank
Frank
Frank
Frank
Frank
Przemysław Woźniak
03/16/2022, 5:45 AMPrzemysław Woźniak
03/16/2022, 9:07 AMFrank
Frank
Przemysław Woźniak
03/16/2022, 10:29 PMimport * as sst from "@serverless-stack/resources";
import { CommonInfraComponents } from "../utils/stackUtils/CommonInfraComponents"; //place with all predefined infra stuff like security Groups and Subnets
import * as cache from "@aws-cdk/aws-elasticache";
export default class RedisCacheStack extends sst.Stack {
public readonly redisUrl: string;
public readonly redisPort: string;
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const commonInfraComponents = CommonInfraComponents(this);
const redisSubnetGroup = new cache.CfnSubnetGroup(
this,
"ElasticCacheRedisSubnetGroup",
{
cacheSubnetGroupName: "ElastiCacheRedisSubnetGroup",
subnetIds: [commonInfraComponents.sn_int_1.subnetId, commonInfraComponents.sn_int_2.subnetId],
description: "Redis subnet group for App Cache"
}
);
const redisCluster = new cache.CfnCacheCluster(
this,
`ElastiCacheRedis`,
{
engine: "redis",
cacheNodeType: "cache.t3.micro", //make env depended
autoMinorVersionUpgrade: true,
numCacheNodes: 1, //make env depended
cacheSubnetGroupName: redisSubnetGroup.cacheSubnetGroupName,
vpcSecurityGroupIds: [
commonInfraComponents.sg_apps_internet_rds.securityGroupId
]
}
);
redisCluster.addDependsOn(redisSubnetGroup);
this.redisUrl = redisCluster.attrRedisEndpointAddress;
this.redisPort = redisCluster.attrRedisEndpointPort;
}
}
Frank