使用 AWS CloudFormation 添加选项组
Adding an option group using AWS CloudFormation
我正在构建一个 CloudFormation 模板,它将创建一个 SQL 服务器数据库(使用 RDS)和多可用区选项(因此它在不同的可用区维护一个同步备用副本)。
但是,为了使这项工作正常进行,我需要将数据库实例与具有镜像选项的选项组相关联。无法在任何地方找到如何使用 CloudFormation 模板创建选项组。
如何在 CloudFormation 模板中创建选项组?
CloudFormation 模板尚不支持复制组功能。因此,唯一可能的方法是创建一个外部 python 脚本,该脚本将使用 Boto lib
创建复制组
如何创建 Redis 复制组的示例
import boto.elasticache
import time
import sys
connection = boto.elasticache.connect_to_region('ap-southeast-2')
connection.create_cache_subnet_group(
"Redis-Subnet-Group-Test",
"Redis cluster subnet",
["subnet-72313306", "subnet-7a06e01f"]
)
connection.create_cache_cluster(
"Redis-Master-Test",
num_cache_nodes = 1,
cache_node_type = "cache.t1.micro",
engine = "redis",
engine_version = "2.6.13",
cache_subnet_group_name = "Redis-Subnet-Group-Test",
security_group_ids = ["sg-07ff1962"],
preferred_availability_zone = "ap-southeast-2a",
preferred_maintenance_window = "tue:01:00-tue:02:00",
auto_minor_version_upgrade = True
)
counter = 0
while counter < 35: # Wait for the cache cluster (redis master) to become available before creating the replication group
counter = counter + 1
clusterDesc = connection.describe_cache_clusters(cache_cluster_id = "Redis-Master-Test")
clusterStatus = clusterDesc["DescribeCacheClustersResponse"]["DescribeCacheClustersResult"]["CacheClusters"][0]["CacheClusterStatus"];
if "available" not in clusterStatus:
time.sleep(10)
elif "available" in clusterStatus:
break
else: # Just roll back on timeout
connection.delete_cache_cluster("Redis-Master-Test")
connection.delete_cache_subnet_group("Redis-Subnet-Group-Test")
sys.exit(1)
connection.create_replication_group("Redis-Replicas-Test", "Redis-Master-Test", "Redis-Replication-Group")
connection.create_cache_cluster(
"Redis-Replica-Test",
num_cache_nodes = 1,
replication_group_id = "Redis-Replicas-Test",
cache_node_type = "cache.t1.micro",
engine = "redis",
engine_version = "2.6.13",
cache_subnet_group_name = "Redis-Subnet-Group-Test",
security_group_ids = ["sg-07ff1962"],
preferred_availability_zone = "ap-southeast-2b",
preferred_maintenance_window = "tue:01:00-tue:02:00",
auto_minor_version_upgrade = True
)
截至目前,CloudFormation 不支持选项组。如果需要在模板中创建数据库,可以预先创建带有cli
的选项组,并将其设置为参数。这样您就可以正确填充 AWS::RDS::DBInstance
资源的 OptionGroupName
值。
我正在构建一个 CloudFormation 模板,它将创建一个 SQL 服务器数据库(使用 RDS)和多可用区选项(因此它在不同的可用区维护一个同步备用副本)。
但是,为了使这项工作正常进行,我需要将数据库实例与具有镜像选项的选项组相关联。无法在任何地方找到如何使用 CloudFormation 模板创建选项组。
如何在 CloudFormation 模板中创建选项组?
CloudFormation 模板尚不支持复制组功能。因此,唯一可能的方法是创建一个外部 python 脚本,该脚本将使用 Boto lib
创建复制组如何创建 Redis 复制组的示例
import boto.elasticache
import time
import sys
connection = boto.elasticache.connect_to_region('ap-southeast-2')
connection.create_cache_subnet_group(
"Redis-Subnet-Group-Test",
"Redis cluster subnet",
["subnet-72313306", "subnet-7a06e01f"]
)
connection.create_cache_cluster(
"Redis-Master-Test",
num_cache_nodes = 1,
cache_node_type = "cache.t1.micro",
engine = "redis",
engine_version = "2.6.13",
cache_subnet_group_name = "Redis-Subnet-Group-Test",
security_group_ids = ["sg-07ff1962"],
preferred_availability_zone = "ap-southeast-2a",
preferred_maintenance_window = "tue:01:00-tue:02:00",
auto_minor_version_upgrade = True
)
counter = 0
while counter < 35: # Wait for the cache cluster (redis master) to become available before creating the replication group
counter = counter + 1
clusterDesc = connection.describe_cache_clusters(cache_cluster_id = "Redis-Master-Test")
clusterStatus = clusterDesc["DescribeCacheClustersResponse"]["DescribeCacheClustersResult"]["CacheClusters"][0]["CacheClusterStatus"];
if "available" not in clusterStatus:
time.sleep(10)
elif "available" in clusterStatus:
break
else: # Just roll back on timeout
connection.delete_cache_cluster("Redis-Master-Test")
connection.delete_cache_subnet_group("Redis-Subnet-Group-Test")
sys.exit(1)
connection.create_replication_group("Redis-Replicas-Test", "Redis-Master-Test", "Redis-Replication-Group")
connection.create_cache_cluster(
"Redis-Replica-Test",
num_cache_nodes = 1,
replication_group_id = "Redis-Replicas-Test",
cache_node_type = "cache.t1.micro",
engine = "redis",
engine_version = "2.6.13",
cache_subnet_group_name = "Redis-Subnet-Group-Test",
security_group_ids = ["sg-07ff1962"],
preferred_availability_zone = "ap-southeast-2b",
preferred_maintenance_window = "tue:01:00-tue:02:00",
auto_minor_version_upgrade = True
)
截至目前,CloudFormation 不支持选项组。如果需要在模板中创建数据库,可以预先创建带有cli
的选项组,并将其设置为参数。这样您就可以正确填充 AWS::RDS::DBInstance
资源的 OptionGroupName
值。