create_cache_cluster ( $cache_cluster_id, $num_cache_nodes, $cache_node_type, $engine, $opt )

Creates a new Cache Cluster.

Access

public

Parameters

Parameter

Type

Required

Description

$cache_cluster_id

string

Required

The Cache Cluster identifier. This parameter is stored as a lowercase string. Constraints:

  • Must contain from 1 to 20 alphanumeric characters or hyphens.
  • First character must be a letter.
  • Cannot end with a hyphen or contain two consecutive hyphens.

Example: mycachecluster

$num_cache_nodes

integer

Required

The number of Cache Nodes the Cache Cluster should have.

$cache_node_type

string

Required

The compute and memory capacity of nodes in a Cache Cluster. Valid values: cache.t1.micro | cache.m1.small | cache.m1.medium | cache.m1.large | cache.m1.xlarge | cache.m3.xlarge | cache.m3.2xlarge | cache.m2.xlarge | cache.m2.2xlarge | cache.m2.4xlarge | cache.c1.xlarge

$engine

string

Required

The name of the cache engine to be used for this Cache Cluster.

Currently, memcached is the only cache engine supported by the service.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • EngineVersion - string - Optional - The version of the cache engine to be used for this cluster.
  • CacheParameterGroupName - string - Optional - The name of the cache parameter group to associate with this Cache cluster. If this argument is omitted, the default CacheParameterGroup for the specified engine will be used.
  • CacheSubnetGroupName - string - Optional - The name of the Cache Subnet Group to be used for the Cache Cluster. Use this parameter only when you are creating a cluster in an Amazon Virtual Private Cloud (VPC).
  • CacheSecurityGroupNames - string|array - Optional - A list of Cache Security Group Names to associate with this Cache Cluster. Use this parameter only when you are creating a cluster outside of an Amazon Virtual Private Cloud (VPC). Pass a string for a single value, or an indexed array for multiple values.
  • SecurityGroupIds - string|array - Optional - Specifies the VPC Security Groups associated with the Cache Cluster. Use this parameter only when you are creating a cluster in an Amazon Virtual Private Cloud (VPC). Pass a string for a single value, or an indexed array for multiple values.
  • PreferredAvailabilityZone - string - Optional - The EC2 Availability Zone that the Cache Cluster will be created in. All cache nodes belonging to a cache cluster are placed in the preferred availability zone. Default: System chosen (random) availability zone.
  • PreferredMaintenanceWindow - string - Optional - The weekly time range (in UTC) during which system maintenance can occur. Example: sun:05:00-sun:09:00
  • Port - integer - Optional - The port number on which each of the Cache Nodes will accept connections.
  • NotificationTopicArn - string - Optional - The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent.

    The Amazon SNS topic owner must be the same as the Cache Cluster owner.

  • AutoMinorVersionUpgrade - boolean - Optional - Indicates that minor engine upgrades will be applied automatically to the Cache Cluster during the maintenance window. Default: true
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

End-to-end flow of setting up a new cluster, retrieving data, and shutting it all down.

$elasticache = new AmazonElastiCache();

// Create a new security group
$elasticache->batch()->create_cache_security_group(
	'my-security-group',
	'This is a memcached security group.'
);

// Create a new parameter group
$elasticache->batch()->create_cache_parameter_group(
	'my-param-group',
	'memcached1.4',
	'This is a memcached parameter group.'
);

// Send requests
$responses = $elasticache->batch()->send(true);
if (!$responses->areOK())
{
	die('Either the security or parameter groups failed to be created.');
}

$response = $elasticache->create_cache_cluster(
	'my-cluster',  # cluster node
	2,                      # number of nodes
	'cache.m1.large',       # instance type
	'memcached',            # cache engine
	'my-secgroup', # security group
	array(
		'CacheParameterGroupName' => 'my-paramgroup',
		'AutoMinorVersionUpgrade' => 'true'
	)
);
if (!$response->isOK())
{
	print_r($response);
	die('Failed to create new cache cluster.');
}

do {
	sleep(20);

	$response = $elasticache->describe_cache_clusters(array(
		'CacheClusterId' => 'my-cluster'
	));

	$status = (string) $response->body
	                            ->DescribeCacheClustersResult
	                            ->CacheClusters
	                            ->CacheCluster
	                            ->CacheClusterStatus;
}
while ($status !== 'available');

// Display parameter group
echo (string) $response->body
                       ->DescribeCacheClustersResult
                       ->CacheClusters
                       ->CacheCluster
                       ->CacheParameterGroup
                       ->CacheParameterGroupName
                       . PHP_EOL;

// Display security group
echo (string) $response->body
                       ->DescribeCacheClustersResult
                       ->CacheClusters
                       ->CacheCluster
                       ->CacheSecurityGroups
                       ->CacheSecurityGroup
                       ->CacheSecurityGroupName
                       . PHP_EOL;

// Clean-up
$response = $elasticache->delete_cache_cluster('my-cluster');
if (!$response->isOK())
{
	print_r($response);
	die('Cluster deletion was unsuccessful.');
}
else
{
	// Wait until the cluster responds with a 404 error
	do {
		sleep(20);

		$response = $elasticache->describe_cache_clusters(array(
			'CacheClusterId' => 'my-cluster'
		));
	}
	while ($response->status !== 404);

	// Delete the security and parameter groups
	$elasticache->batch()->delete_cache_security_group('my-security-group');
	$elasticache->batch()->delete_cache_parameter_group('my-param-group');

	$responses = $elasticache->batch()->send(true);
	if (!$responses->areOK())
	{
		print_r($responses);
		die('Group deletions were unsuccessful.');
	}
}

Source

Method defined in services/elasticache.class.php | Toggle source view (28 lines) | View on GitHub

public function create_cache_cluster($cache_cluster_id, $num_cache_nodes, $cache_node_type, $engine, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['CacheClusterId'] = $cache_cluster_id;
    $opt['NumCacheNodes'] = $num_cache_nodes;
    $opt['CacheNodeType'] = $cache_node_type;
    $opt['Engine'] = $engine;
    
    // Optional list (non-map)
    if (isset($opt['CacheSecurityGroupNames']))
    {
        $opt = array_merge($opt, CFComplexType::map(array(
            'CacheSecurityGroupNames' => (is_array($opt['CacheSecurityGroupNames']) ? $opt['CacheSecurityGroupNames'] : array($opt['CacheSecurityGroupNames']))
        ), 'member'));
        unset($opt['CacheSecurityGroupNames']);
    }
    
    // Optional list (non-map)
    if (isset($opt['SecurityGroupIds']))
    {
        $opt = array_merge($opt, CFComplexType::map(array(
            'SecurityGroupIds' => (is_array($opt['SecurityGroupIds']) ? $opt['SecurityGroupIds'] : array($opt['SecurityGroupIds']))
        ), 'member'));
        unset($opt['SecurityGroupIds']);
    }

    return $this->authenticate('CreateCacheCluster', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback