AWS CloudFormationのAmazon Redshift対応、ついに来た!

2014.02.11

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

本日付けでCloudFormationがAmazon RedshiftとElastic Beanstalkに対応するようになりました。これまでは管理コンソールやAWS CLIで扱っていたRedshiftの諸々の要素が、これでCloudFormationでも扱えるようになります。当エントリではそれら対応するようになったリソースの一覧を見てみると共に、実際にCloudFormationを実行してみてどんな感じなるのかを見てみたいと思います。

目次

Amazon Redshiftに関する CloudFormation resource一覧

今回登場したの以下リソースとなります。

AWS::Redshift::ClusterSubnetGroup

Amazon Redshiftクラスタを配備するクラスタのサブネットグループを定義します。

Syntax:

{
  "Type": "AWS::Redshift::ClusterSubnetGroup",
  "Properties": {
    "Description" : String,
    "SubnetIds" : [ String, ... ]
  }
}

記述例:

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "Amazon Redshift Cluster Demo(Cluster Subnet-group).",

  "Resources" : {
    "RedshiftClusterSubnet" : {
      "Type" : "AWS::Redshift::ClusterSubnetGroup",
      "Properties" : {
        "Description" : "Redshift Cluster Subnet.",
        "SubnetIds" : [ "subnet-xxxxxxxx", "subnet-yyyyyyyy" ]
      }
    }
  },

  "Outputs" : {
    "SubnetGroup" : {
      "Description" : "Output of RedshiftClusterSubnet",
      "Value" :  { "Ref" : "RedshiftClusterSubnet" }
    }
  }
}

実行結果:

cloudformation-redshift-01

AWS::Redshift::ClusterSecurityGroup

Amazon Redshiftクラスタへのアクセス制御を行うセキュリティグループを設定します。このリソースはそのルールを入れる"器"のみを定義します。

{
  "Type": "AWS::Redshift::ClusterSecurityGroup",
  "Properties": {
    "Description" : String
  }
}

AWS::Redshift::ClusterSecurityGroupIngress

Amazon Redshiftクラスタへのアクセス制御を行うセキュリティグループを設定します。上記で作成した"器"に入る、実際のルールに該当する部分をこのリソースで作成します。

{
  "Type": "AWS::Redshift::ClusterSecurityGroupIngress",
  "Properties": {
    "ClusterSecurityGroupName" : String,
    "CIDRIP" : String,
    "EC2SecurityGroupName" : String,
    "EC2SecurityGroupOwnerId" : String
  }
}

SecurityGroup及びSecurityGroupIngressを試してみましたが、実行時にこんなエラーが出てました。この両要素はEC2 Classic環境でのみ利用可能な要素のようですね。

cloudformation-redshift-02

こちらがRedshiftに於けるEC2 Classicでセキュリティグループを作成する場合の画面。当エントリではEC2 Classicに関する手順は割愛したいと思います。

cloudformation-redshift-03

AWS::Redshift::ClusterParameterGroup

Amazon Redshiftクラスタが参照・利用する事になるパラメータグループです。

Syntax:

{
  "Type": "AWS::Redshift::ClusterParameterGroup",
  "Properties": {
    "Description" : String,
    "ParameterGroupFamily" : String,
    "Parameters" : [ Parameter, ... ]
  }
}

記述例:

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "Amazon Redshift Cluster Demo(Cluster Parameter-group).",

  "Resources" : {
    "RedshiftParameterGroup" : {
      "Type" : "AWS::Redshift::ClusterParameterGroup",
      "Properties" : {
        "Description" : "Redshift ParameterGroup.",
        "ParameterGroupFamily" : "redshift-1.0",
        "Parameters" : [
          { "ParameterName" : "datestyle", "ParameterValue" : "ISO, MDY" },
          { "ParameterName" : "enable_user_activity_logging", "ParameterValue" : "false" },
          { "ParameterName" : "extra_float_digits", "ParameterValue" : "0" },
          { "ParameterName" : "query_group", "ParameterValue" : "default" },
          { "ParameterName" : "require_ssl", "ParameterValue" : "false" },
          { "ParameterName" : "search_path", "ParameterValue" : "$user, public" },
          { "ParameterName" : "statement_timeout", "ParameterValue" : "0" },
          { "ParameterName" : "wlm_json_configuration", "ParameterValue" : "[{\"query_concurrency\":5}]" }
        ]
      }
    }
  },

  "Outputs" : {
    "RedshiftParameterGroup" : {
      "Description" : "Output of RedshiftParameterGroup",
      "Value" :  { "Ref" : "RedshiftParameterGroup" }
    }
  }
}

実行結果:

cloudformation-redshift-04

AWS::Redshift::Cluster

クラスタ本体です。

Syntax:

{
  "Type": "AWS::Redshift::Cluster",
  "Properties": {
    "AllowVersionUpgrade" : Boolean,
    "AutomatedSnapshotRetentionPeriod" : Integer,
    "AvailabilityZone" : String,
    "ClusterParameterGroupName" : String,
    "ClusterSecurityGroups" : [ String, ... ],
    "ClusterSubnetGroupName" : String,
    "ClusterType" : String,
    "ClusterVersion" : String,
    "DBName" : String,
    "ElasticIp" : String,
    "Encrypted" : Boolean,
    "HsmClientCertificateIdentifier" : String,
    "HsmConfigurationIdentifier" : String,
    "MasterUsername" : String,
    "MasterUserPassword" : String,
    "NodeType" : String,
    "NumberOfNodes" : Integer,
    "OwnerAccount" : String,
    "Port" : Integer,
    "PreferredMaintenanceWindow" : String,
    "PubliclyAccessible" : Boolean,
    "SnapshotClusterIdentifier" : String,
    "SnapshotIdentifier" : String,
    "VpcSecurityGroupIds" : [ String, ... ]
  }
}

記述例:上記手順でSubnetGroup及びParameterGroupを生成しているものとしています。

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "Amazon Redshift Cluster Demo(Cluster).",

  "Resources" : {
    "RedshiftCluster" : {
      "Type": "AWS::Redshift::Cluster",
      "Properties": {
        "AllowVersionUpgrade" : false,
        "AutomatedSnapshotRetentionPeriod" : 1,
        "AvailabilityZone" : "us-west-2a",
        "ClusterParameterGroupName" : "(上記過程で作成したパラメータグループの名前)",
        "ClusterSubnetGroupName" : "(上記過程で作成したサブネットグループの名前)",
        "ClusterType" : "multi-node",
        "ClusterVersion" : "1.0",
        "DBName" : "cmredshiftdb",
        "Encrypted" : false,
        "MasterUsername" : "cmrsuser",
        "MasterUserPassword" : "(*********)",
        "NodeType" : "dw2.large",
        "NumberOfNodes" : 2,
        "Port" : 5439,
        "PubliclyAccessible" : true,
        "VpcSecurityGroupIds" : [ "sg-XXXXXXXXX" ]
      }
    }
  },

  "Outputs" : {
    "RedshiftCluster" : {
      "Description" : "Output of RedshiftCluster",
      "Value" :  { "Ref" : "RedshiftCluster" }
    }
  }
}

実行結果:

cloudformation-redshift-05

Redshiftクラスタの内容はこのような感じです。ちゃんと作成されていますね。

cloudformation-redshift-06

Public Accessible属性をtrueにしているので、外部からの接続も試してみます。

cloudformation-redshift-07

無事接続完了しました!

cloudformation-redshift-08

ひと通りの確認作業が終わったのでDelete Stackで諸々のインスタンスを削除。

cloudformation-redshift-09

まとめ

以上、AWS CloudFormationのAmazon Redshift対応についてひと通り触ってみました。管理コンソールで1つずつ行わざるを得なかった作業がCloudFormation一発で環境構築出来るようになるのは良いですね。CloudFormationで出来る事・出来ない事もそれぞれあるので、その辺りはAWS CLIと組み合わせる事で更に快適な・スムーズなAmazon Redshiftクラスタ管理が出来るのではと思っております。