-
Notifications
You must be signed in to change notification settings - Fork 45
/
redis.js
47 lines (40 loc) · 1.4 KB
/
redis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const cdk = require('@aws-cdk/core');
const elasticache = require('@aws-cdk/aws-elasticache');
const ec2 = require('@aws-cdk/aws-ec2');
class RedisCluster extends cdk.Construct {
constructor(scope, id, props) {
super(scope, id);
const targetVpc = props.vpc;
// Define a group for telling Elasticache which subnets to put cache nodes in.
const subnetGroup = new elasticache.CfnSubnetGroup(this, `${id}-subnet-group`, {
description: `List of subnets used for redis cache ${id}`,
subnetIds: targetVpc.privateSubnets.map(function(subnet) {
return subnet.subnetId;
})
});
// The security group that defines network level access to the cluster
this.securityGroup = new ec2.SecurityGroup(this, `${id}-security-group`, { vpc: targetVpc });
this.connections = new ec2.Connections({
securityGroups: [this.securityGroup],
defaultPort: new ec2.Port({
protocol: ec2.Protocol.TCP,
fromPort: 6379,
toPort: 6379
})
});
// The cluster resource itself.
this.cluster = new elasticache.CfnCacheCluster(this, `${id}-cluster`, {
cacheNodeType: 'cache.t2.micro',
engine: 'redis',
numCacheNodes: 1,
autoMinorVersionUpgrade: true,
cacheSubnetGroupName: subnetGroup.ref,
vpcSecurityGroupIds: [
this.securityGroup.securityGroupId
]
});
}
}
module.exports = {
Cluster: RedisCluster
};