AWS::ElastiCache::CacheCluster 对比 AWS::ElastiCache::ReplicationGroup
AWS::ElastiCache::CacheCluster vs AWS::ElastiCache::ReplicationGroup
我之前用这个通过cloudformation成功的建立了一个redis实例:
"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 最近将 Redis 升级为使用 AtRestEncryption
、AuthToken
和 TransitEncryption
我尝试在上面的代码中包含这些内容,但仅根据 this AWS::ElastiCache::ReplicationGroup
接受这些参数。
如何使用 AWS::ElastiCache::ReplicationGroup
创建单个 Redis 实例?
根据文档,
您需要创建 ReplicationGroup 而不是 CacheCluster,并将 NumNodeGroups 设置为 1 并将 AutomaticFailoverEnabled 设置为 false
。
这两个值都是默认值,因此您可以省略它们。
API Documentation 有更多关于单节点参数值的详细信息。
您需要创建在缓存集群上引用的复制组作为写入操作的主要复制组。
完整代码脚本:
"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"
}
}
}
我之前用这个通过cloudformation成功的建立了一个redis实例:
"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 最近将 Redis 升级为使用 AtRestEncryption
、AuthToken
和 TransitEncryption
我尝试在上面的代码中包含这些内容,但仅根据 this AWS::ElastiCache::ReplicationGroup
接受这些参数。
如何使用 AWS::ElastiCache::ReplicationGroup
创建单个 Redis 实例?
根据文档,
您需要创建 ReplicationGroup 而不是 CacheCluster,并将 NumNodeGroups 设置为 1 并将 AutomaticFailoverEnabled 设置为 false
。
这两个值都是默认值,因此您可以省略它们。
API Documentation 有更多关于单节点参数值的详细信息。
您需要创建在缓存集群上引用的复制组作为写入操作的主要复制组。 完整代码脚本:
"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"
}
}
}