Skip to content

ServerlessCache

Source: src/AWS/ElastiCache/ServerlessCache.ts

An Amazon ElastiCache serverless cache (valkey, redis, or memcached).

Serverless caches scale storage and compute automatically and are only reachable from inside a VPC. They are metered while they exist (with a monthly minimum), so set cacheUsageLimits and destroy caches you are not using.

Valkey Cache with Cost-Control Limits

const cache = yield* ServerlessCache("SessionCache", {
engine: "valkey",
cacheUsageLimits: {
dataStorage: { maximum: 1 },
ecpuPerSecond: { maximum: 1000 },
},
});

Redis Cache in Specific Subnets

const cache = yield* ServerlessCache("Cache", {
engine: "redis",
majorEngineVersion: "7",
subnetIds: [subnetA.subnetId, subnetB.subnetId],
securityGroupIds: [cacheSecurityGroup.securityGroupId],
});
const connect = yield* ElastiCache.Connect(cache);
// inside a handler:
const { host, port, tls } = yield* connect;