使用AWS CloudFormation添加选项组

时间:2015-04-19 04:10:48

标签: amazon-web-services rds amazon-cloudformation

我正在构建一个CloudFormation模板,该模板将使用多可用区选项创建一个SQL Server数据库(使用RDS)(因此它在另一个可用区中维护一个同步备用副本)。

但是,为了使这项工作,我需要将数据库实例与具有镜像选项的选项组相关联。 Haven能够在任何地方找到如何使用CloudFormation模板创建选项组。

如何在CloudFormation模板中创建选项组?

2 个答案:

答案 0 :(得分:0)

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
)

答案 1 :(得分:0)

截至目前,CloudFormation不支持选项组。如果需要在模板中创建数据库,则可以预先使用cli创建选项组,并将其设置为参数。这样,您就可以正确填充OptionGroupName资源的AWS::RDS::DBInstance值。