Forgot to mention - we did have one project built ...
# help
p
Forgot to mention - we did have one project built in Serverless and creating Redis instance there was quite easy, that's why I'm asking if something similar I can achieve with SST 🙂
f
Hey @Przemysław Woźniak, SST doesn’t have a high level construct for Redis at the moment, you’d use the CDK constructs.
It’s quite straight forward to use CDK constructs in ur SST app.
You can give this a try by adding them to a Stack https://stackoverflow.com/a/58709068
Give it a try. Let me know if it works for you.
p
Thanks! Will try it out today and for sure let you know 🙂
@Frank as you said, straightforward. 15 minutes of work, 10 minutes for AWS to setup t3.micro cluster (bad weather I think 😄 ) and I have my cache available to use. Thanks again!
f
Awesome!
Do you mind sharing a snippet of ur code? I’m sure other will find it useful.
p
Sure!
Copy code
import * 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;
    }
}
f
Thanks @Przemysław Woźniak! Appreciate it.