LoginSignup
9
5

More than 5 years have passed since last update.

今更ながら、CloudFormation で ElastiCache を構築した。

Last updated at Posted at 2018-08-15

はじめに

ElastiCache を使いたいって話が出たので、コンソールからポチポチ作ろうと思ったんです。
どうせならと思い、CloudFormation を使ってデプロイできるようにすれば、何回も同じことしなくてもいいっしょ、てな考えから作ってみました。

やってみた

作るもの

  • Memcached(Multi AZ)
  • Redis Cluster

テンプレート

JSON は人が書くものじゃないと思っているので、yaml で。初めて作ったんでこんなもんでしょ。
VPC とサブネットは作成済みだったんで、ID を指定しているだけです。

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  Subnet1:
    Type: String
    Default: [ゾーンAのサブネットID]
  Subnet2:
    Type: String
    Default: [ゾーンCのサブネットID]
  SGName:
    Type: String
    Default: [EC2メニューで作ったセキュリティグループID]
  InstanceType:
    Type: String
    Default: cache.r4.large
Resources:
  ECacheSubnet:
    Type: 'AWS::ElastiCache::SubnetGroup'
    Properties:
      CacheSubnetGroupName: elasticache-subnet-group
      Description: elasticache-subnet-group
      SubnetIds:
        - !Ref Subnet1
        - !Ref Subnet2
  ECacheMemdPG:
    Type: 'AWS::ElastiCache::ParameterGroup'
    Properties:
      CacheParameterGroupFamily: memcached1.4
      Description: "memcached cluster Params"
  ECacheRedisPG:
    Type: 'AWS::ElastiCache::ParameterGroup'
    Properties:
      CacheParameterGroupFamily: Redis4.0
      Description: "redis cluster Params"
      Properties:
        cluster-enabled: "yes"
  ECacheMemd:
    Type: 'AWS::ElastiCache::CacheCluster'
    Properties:
      AutoMinorVersionUpgrade: false
      AZMode: cross-az
      CacheNodeType: !Ref InstanceType
      CacheParameterGroupName: !Ref ECacheMemdPG
      CacheSubnetGroupName: !Ref ECacheSubnet
      ClusterName: memcached-cluster-01
      Engine: memcached
      EngineVersion: 1.4.34
      NumCacheNodes: 2
      Port: 11211
      PreferredAvailabilityZones:
        - ap-northeast-1a
        - ap-northeast-1c
      PreferredMaintenanceWindow: 'sun:17:00-sun:20:00'
      VpcSecurityGroupIds:
        - !Ref SGName
  ECacheRedis:
    Type: 'AWS::ElastiCache::ReplicationGroup'
    Properties:
      AutomaticFailoverEnabled: true
      AutoMinorVersionUpgrade: false
      CacheNodeType: !Ref InstanceType
      CacheParameterGroupName: !Ref ECacheRedisPG
      CacheSubnetGroupName: !Ref ECacheSubnet
      Engine: redis
      EngineVersion: 4.0.10
      NodeGroupConfiguration:
        - PrimaryAvailabilityZone: ap-northeast-1a
          ReplicaAvailabilityZones:
            - ap-northeast-1a
            - ap-northeast-1c
        - PrimaryAvailabilityZone: ap-northeast-1c
          ReplicaAvailabilityZones:
            - ap-northeast-1c
            - ap-northeast-1a
      NumNodeGroups: 2
      Port: 6379
      PreferredMaintenanceWindow: 'sun:17:00-sun:20:00'
      ReplicationGroupDescription: redis-cluster-01
      ReplicationGroupId: redis-cluster-01
      ReplicasPerNodeGroup: 2
      SecurityGroupIds:
        - !Ref SGName

出来なかったこと

  • パラメータグループに任意の名前を付けることができなかった
    • CLI だとできるから、CloudFormation が未対応な模様

やってみた感想

初めて CloudFormation を使ったんですが、ドキュメントをちゃんと読めばできる。
ただ、CloudFormation が対応していないものがあるとは思ってなかったから、そこは CLI に頼るか、機能が追加されるのを待つか。

仲間募集中

弊社ではエンジニアを募集中です。インフラからアプリ、ユーザサポートまで幅広く業務を行ってます。
https://www.nittsu-infosys.com/recruit/2019/index.html

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5