Reputation: 305
I used this earlier to get a redis instance up successfully through cloudformation:
"RedisCache": {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"ClusterName": {
"Fn::Join": ["-", [ {
"Ref": "EnvType"
}, {
"Ref": "EnvVersion"
}
]]
},
"AutoMinorVersionUpgrade": "true",
"AZMode": "single-az",
"CacheNodeType": "cache.t2.medium",
"Engine": "redis",
"EngineVersion": "3.2.6",
"NumCacheNodes": "1",
"PreferredAvailabilityZone": "us-west-2a",
"PreferredMaintenanceWindow": "sun:04:30-sun:05:30",
"CacheSubnetGroupName": "redis-test-subnet-group",
"VpcSecurityGroupIds": ["sg-group1", "sg-group2"]
}
},
AS AWS has recently upgraded Redis to use AtRestEncryption
,AuthToken
and TransitEncryption
I tried including those in the above code, but as per this only AWS::ElastiCache::ReplicationGroup
accepts those parameters.
How do I create a single Redis instance using AWS::ElastiCache::ReplicationGroup
?
Upvotes: 4
Views: 3114
Reputation: 41
You need to create replication group referenced on cache cluster as a primary one for write operations. Full code script:
"cache": {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"CacheSubnetGroupName": {
"Ref": "cacheSubnetGroup"
},
"AutoMinorVersionUpgrade": "true",
"Engine": {
"Ref": "CacheEngine"
},
"CacheNodeType": {
"Ref": "CacheType"
},
"NumCacheNodes": {
"Ref": "CacheNodes"
},
"VpcSecurityGroupIds": [
{
"Fn::GetAtt": [
"cacheSecurityGroup",
"GroupId"
]
}
],
"PreferredAvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "9bae52e5-d091-42f2-9473-8a422efd6ced"
}
}
},
"cacheSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Elasticache Security Group",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": {
"Ref": "CachePort"
},
"ToPort": {
"Ref": "CachePort"
},
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "VPC"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "4e5fb112-e80a-4c65-b68a-c136850d3933"
}
}
},
"cacheSubnetGroup": {
"Type": "AWS::ElastiCache::SubnetGroup",
"Properties": {
"Description": "Cache Subnet Group",
"SubnetIds": [
{
"Ref": "PublicSubnet1"
},
{
"Ref": "PublicSubnet2"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ac3d8db2-5aa2-4998-8e7d-acfeb9e21a88"
}
}
},
"cacheReplicationGroup": {
"Type": "AWS::ElastiCache::ReplicationGroup",
"Properties": {
"ReplicationGroupDescription": "Cache Replication Group",
"AutomaticFailoverEnabled": "true",
"NumCacheClusters": {
"Ref": "CacheReplicaNodes"
},
"PrimaryClusterId": {
"Ref": "cache"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "3e76370e-4996-43b6-9373-22ef20a9b2ee"
}
}
}
Upvotes: 4
Reputation: 8057
From documentation,
you need to create ReplicationGroup instead of CacheCluster and set NumNodeGroups to 1 and AutomaticFailoverEnabled to false
.
Both values are the default, so you can omit them.
The API Documentation has more details on the parameter values for single node.
Upvotes: 4