Created
July 16, 2016 05:24
-
-
Save akira345/63fc160d92170fdacfa9c6790adb1797 to your computer and use it in GitHub Desktop.
AWS ElasticCache上にmemcacheクラスタを構築するサンプルです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# ElasticCacheにmemcacheクラスタを構築するスクリプトです。 | |
# 要 AWS SDK for Ruby V2 | |
require 'aws-sdk-core' | |
require 'yaml' | |
require 'pp' | |
config = YAML.load(File.read('config.yml')) | |
Aws.config[:credentials] = Aws::Credentials.new(config['access_key_id'], config['secret_access_key']) | |
elasticache = Aws::ElastiCache::Client.new(region: config['region']) | |
#### 設定 #################################### | |
CACHE_CLUSTER_ID = 'SampleCache' # キャッシュクラスタ名 | |
NUMBER_CACHE_NODE = 1 # 起動するキャッシュノード数 | |
CACHE_NODE_TYPE = 'cache.t2.micro' # ノードインスタンスタイプ | |
ENGINE_VERSION = '1.4.24' # memcacheのバージョン | |
CACHE_PARAMETER_GROUP_NAME = 'default.memcached1.4' # パラメタグループ | |
CACHE_SUBNET_GROUP_NAME = 'cache-subnetg' # ElasticCache用サブネットグループ名 | |
CACHE_SECURITY_GROUP_IDS = ['sg-xxxxxxx'] # 適用するセキュリティグループID | |
MENTENANCE_WINDOW = 'sun:05:00-sun:09:00' # パッチあてなどメンテナンス時間指定(UTC) | |
############################################## | |
elasticache.create_cache_cluster(cache_cluster_id: CACHE_CLUSTER_ID, # required | |
az_mode: 'single-az', # accepts single-az, cross-az | |
num_cache_nodes: NUMBER_CACHE_NODE, | |
cache_node_type: CACHE_NODE_TYPE, | |
engine: 'memcached', | |
engine_version: ENGINE_VERSION, | |
cache_parameter_group_name: CACHE_PARAMETER_GROUP_NAME, | |
cache_subnet_group_name: CACHE_SUBNET_GROUP_NAME, | |
security_group_ids: CACHE_SECURITY_GROUP_IDS, | |
tags: [ | |
{ | |
key: 'Name', | |
value: CACHE_CLUSTER_ID | |
} | |
], | |
preferred_maintenance_window: MENTENANCE_WINDOW, | |
port: 11211, # ポート番号 | |
auto_minor_version_upgrade: true) #自動マイナーアップグレードするか? | |
puts "Memcache作成中・・・" | |
resp = elasticache.wait_until(:cache_cluster_available, cache_cluster_id: 'TestCache') | |
puts resp.cache_clusters[0].configuration_endpoint.address | |
puts "作成完了!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment