AlibabaCloudのAuto Scaling x SLB x RDSをやってみる(ROS版)

AlibabaCloudのAuto Scaling x SLB x RDSをやってみる(ROS版)

# はじめに
[AlibabaCloudのAuto Scaling x SLBをやってみる(ROS版)](https://qiita.com/wa-ta-ru/items/b27f75cf8d82d1f6a3c7)
でやった、テンプレートにRDSを追加してみます。

# JSONテンプレート
こちらのテンプレートで起動が可能です。

```json
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "poc",
  "Metadata": {
    "RosGraphicElement-3": {
      "x": 404,
      "y": 117,
      "width": 386,
      "height": 270
    },
    "RosGraphicElement-1": {
      "x": 39,
      "y": 39
    },
    "RosGraphicElement-2": {
      "x": 147,
      "y": 39
    },
    "RosGraphicElement-5": {
      "x": 139,
      "y": 359
    },
    "RosGraphicElement-6": {
      "x": 139,
      "y": 359
    },
    "RosGraphicElement-12": {
      "x": 242,
      "y": 237
    },
    "RosGraphicElement-13": {
      "x": 139,
      "y": 237
    },
    "RosGraphicElement-14": {
      "x": 181,
      "y": 133
    }
  },
  "Parameters": {
    "CidrBlock": {
      "Type": "String",
      "AllowedValues": [
        "192.168.0.0/16",
        "172.16.0.0/12",
        "10.0.0.0/8"
      ],
      "Default": "10.0.0.0/8"
    },
    "ImageId": {
      "Type": "String",
      "Description": "ECS Image",
      "Label": "ECS Image",
      "Default": "centos_7_04_64_20G_alibase_201701015.vhd"
    },
    "InstanceType": {
      "Type": "String",
      "Description": "ECS Instance Type",
      "AllowedValues": [
        "ecs.t5-lc2m1.nano"
      ],
      "Label": "ECS Instance Type",
      "Default": "ecs.t5-lc2m1.nano"
    },
    "KeyPair": {
      "Type": "String",
      "Description": "ECS Key Pair",
      "Label": "ECS Key Pair",
      "Default": "aliyun-ap-northeast-1"
    },
    "Engine": {
      "Type": "String",
      "Default": "MySQL",
      "AllowedValues": [
        "MySQL"
      ]
    },
    "EngineVersion": {
      "Type": "String",
      "Default": "5.7",
      "Description": "MySQL：5.6/5.7",
      "AllowedValues": [
        "5.6",
        "5.7"
      ]
    },
    "DBInstanceClass": {
      "Type": "String",
      "Default": "rds.mysql.t1.small",
      "AllowedValues": [
        "mysql.n1.micro.1",
        "mysql.n2.small.1",
        "mysql.n2.medium.1",
        "mysql.n4.medium.1",
        "mysql.n4.large.1",
        "mysql.n4.xlarge.1",
        "mysql.n4.2xlarge.1",
        "mysql.n4.4xlarge.1",
        "mysql.n8.4xlarge.1",
        "mysql.n4.8xlarge.1",
        "mysql.n8.8xlarge.1",
        "rds.mysql.t1.small",
        "rds.mysql.s1.small",
        "rds.mysql.s2.large",
        "rds.mysql.s2.xlarge",
        "rds.mysql.s3.large",
        "rds.mysql.m1.medium",
        "rds.mysql.c1.large",
        "rds.mysql.c1.xlarge",
        "rds.mysql.c2.xlarge",
        "rds.mysql.c2.xlp2",
        "mysql.x8.medium.2",
        "mysql.x8.large.2",
        "mysql.x8.xlarge.2",
        "mysql.x8.2xlarge.2",
        "mysql.x4.large.2",
        "mysql.x4.xlarge.2",
        "mysql.x4.2xlarge.2",
        "mysql.x4.4xlarge.2",
        "rds.mysql.st.d13",
        "rds.mysql.st.h43",
        "mysql.x4.large.3",
        "mysql.x4.xlarge.3",
        "mysql.x4.2xlarge.3",
        "mysql.x4.4xlarge.3"
      ]
    },
    "DBInstanceStorage": {
      "Type": "Number",
      "MinValue": 5,
      "MaxValue": 2000,
      "Default": 10,
      "Description": "Incrementing in every 5G, unit: GB",
      "ConstraintDescription": "Incrementing in every 5G, unit: GB"
    },
    "DBInstanceNetType": {
      "Type": "String",
      "Default": "Intranet",
      "AllowedValues": [
        "Internet",
        "Intranet"
      ]
    },
    "DBUserName": {
      "Type": "String",
      "Default": "dbuser",
      "Description": "Database User Name"
    },
    "DBUserPassword": {
      "Type": "String",
      "Default": "password",
      "Description": "Database User Password"
    }
  },
  "Mappings": {},
  "Conditions": {},
  "Resources": {
    "VPC": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-1"
      },
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "VpcName": {
          "Ref": "ALIYUN::StackName"
        },
        "CidrBlock": "10.0.0.0/8"
      }
    },
    "VSwitch-ECS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-2"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "ecs",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.0.0/24",
        "Description": "ecs",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "VSwitch-SLB": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-3"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "slb",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.1.0/24",
        "Description": "slb",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "SG": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-5"
      },
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "VPC"
        },
        "SecurityGroupName": {
          "Fn::Join": [
            "-",
            [
              {
                "Ref": "ALIYUN::StackName"
              },
              "ecs-sg"
            ]
          ]
        },
        "SecurityGroupEgress": [
          {
            "PortRange": "-1/-1",
            "Priority": 1,
            "IpProtocol": "all",
            "DestCidrIp": "0.0.0.0/0",
            "NicType": "intranet",
            "SecurityGroupId": "0"
          }
        ],
        "SecurityGroupIngress": [
          {
            "PortRange": "-1/-1",
            "Priority": 1,
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "all",
            "NicType": "intranet",
            "SecurityGroupId": "0"
          }
        ]
      }
    },
    "VSwitch-RDS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-6"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "rds",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.2.0/24",
        "Description": "rds",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "ScalingGroup": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-12"
      },
      "Type": "ALIYUN::ESS::ScalingGroup",
      "Properties": {
        "VpcId": {
          "Ref": "VPC"
        },
        "ScalingGroupName": "SSG",
        "RemovalPolicys": [
          "OldestScalingConfiguration",
          "OldestInstance"
        ],
        "MinSize": "2",
        "MaxSize": "2",
        "VSwitchId": {
          "Ref": "VSwitch-ECS"
        },
        "DefaultCooldown": 300
      }
    },
    "ScalingConfiguration": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-13"
      },
      "Type": "ALIYUN::ESS::ScalingConfiguration",
      "Properties": {
        "SystemDiskCategory": "cloud_ssd",
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "SecurityGroupId": {
          "Ref": "SG"
        },
        "ImageId": {
          "Ref": "ImageId"
        },
        "InternetMaxBandwidthOut": 1,
        "IoOptimized": "optimized",
        "ScalingGroupId": {
          "Ref": "ScalingGroup"
        },
        "InternetChargeType": "PayByTraffic",
        "InternetMaxBandwidthIn": 200,
        "ScalingConfigurationName": {
          "Ref": "ALIYUN::StackName"
        }
      }
    },
    "ScalingGroupEnable": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-14"
      },
      "Type": "ALIYUN::ESS::ScalingGroupEnable",
      "Properties": {
        "ScalingConfigurationId": {
          "Ref": "ScalingConfiguration"
        },
        "ScalingGroupId": {
          "Ref": "ScalingGroup"
        }
      }
    },
    "Database": {
      "Type": "ALIYUN::RDS::DBInstance",
      "Properties": {
        "Engine": {
          "Ref": "Engine"
        },
        "EngineVersion": {
          "Ref": "EngineVersion"
        },
        "DBInstanceClass": {
          "Ref": "DBInstanceClass"
        },
        "DBInstanceStorage": {
          "Ref": "DBInstanceStorage"
        },
        "DBInstanceNetType": {
          "Ref": "DBInstanceNetType"
        },
        "SecurityIPList": "0.0.0.0/0",
        "VSwitchId": {
          "Ref": "VSwitch-RDS"
        },
        "VpcId": {
          "Ref": "VPC"
        },
        "AllocatePublicConnection": false
      }
    }
  },
  "Outputs": {
    "VRouterId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "VRouterId"
        ]
      }
    },
    "VSwitch-ECS": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-ECS",
          "VSwitchId"
        ]
      }
    },
    "RouteTableId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "RouteTableId"
        ]
      }
    },
    "VpcId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "VpcId"
        ]
      }
    },
    "VSwitch-SLB": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-ECS",
          "VSwitchId"
        ]
      }
    },
    "VSwitch-RDS": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-RDS",
          "VSwitchId"
        ]
      }
    },
    "ScalingGroupEnable": {
      "Value": {
        "Fn::GetAtt": [
          "ScalingGroupEnable",
          "LifecycleState"
        ]
      }
    },
    "ScalingGroup": {
      "Value": {
        "Fn::GetAtt": [
          "ScalingGroup",
          "ScalingGroupId"
        ]
      }
    },
    "ScalingConfiguration": {
      "Value": {
        "Fn::GetAtt": [
          "ScalingConfiguration",
          "ScalingConfigurationId"
        ]
      }
    },
    "DBInstanceId": {
      "Value": {
        "Fn::GetAtt": [
          "Database",
          "DBInstanceId"
        ]
      }
    },
    "PublicConnectionString": {
      "Value": {
        "Fn::GetAtt": [
          "Database",
          "PublicConnectionString"
        ]
      }
    },
    "PublicPort": {
      "Value": {
        "Fn::GetAtt": [
          "Database",
          "PublicPort"
        ]
      }
    },
    "InnerConnectionString": {
      "Value": {
        "Fn::GetAtt": [
          "Database",
          "InnerConnectionString"
        ]
      }
    },
    "InnerPort": {
      "Value": {
        "Fn::GetAtt": [
          "Database",
          "InnerPort"
        ]
      }
    }
  }
}
```

# はまったところ

`mysql.n1.micro.1`
`rds.mssql.s2.large`
でやっていたら全然起動できない状態になりました。
下記のようなエラーコードがでました。

`Resource CREATE failed: 〜〜〜〜〜 RequestId: XXXXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX
`
とかエラーがでて、長い間はまってました。

調べた結果
[インスタンスタイプリスト - プロダクト紹介| Alibaba Cloud ドキュメントセンター](https://jp.alibabacloud.com/help/doc-detail/26312.htm)
と照らし合わせて、起動するRDSに適したインスタンスタイプにしないとダメでした。
ここは今後詳しくしらべてまとめたいと思います。

# まとめ
サンプルテンプレートに
`ess_1slb_2rds_2ecs`
というものがありました。
こちらを起動しても、今回に近しい構成になります。

学習してきた結果として、そこに行き着いたので
いままでの記事を逆に辿れば、どこをやっていけばいいのかポイントがわかりやすくなると思います。