LoginSignup
2
0

More than 5 years have passed since last update.

AlibabaCloudのECSを東京リージョンの最安値で起動してみる!(ROS版)

Last updated at Posted at 2018-05-13

はじめに

AlibabaCloudのECSを東京リージョンの最安値で起動してみる! - Qiita

ECSで起動したのを前に書きました。
今回は、ROSで起動をしてみます。

インスタンスタイプが最小でなかったので

テンプレート

AlibabaCloudのResource Orchestration Service(ROS)を触ってみる。 - Qiita
のテンプレートを改修しました。

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "poc",
  "Metadata": {
    "RosGraphicElement-1": {
      "x": 326,
      "y": 208,
      "width": 368,
      "height": 245
    },
    "RosGraphicElement-2": {
      "x": 93,
      "y": 147
    },
    "RosGraphicElement-3": {
      "x": 39,
      "y": 39
    },
    "RosGraphicElement-4": {
      "x": 473,
      "y": 247
    },
    "RosGraphicElement-5": {
      "x": 201,
      "y": 147
    },
    "RosGraphicElement-6": {
      "x": 255,
      "y": 39
    }
  },
  "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"
    },
    "VpcName": {
      "Type": "String",
      "Description": "The VPC name",
      "MinLength": 2,
      "ConstraintDescription": "[2, 128] English or Chinese letters",
      "MaxLength": 128,
      "Default": "poc"
    },
    "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.xn4.small"
      ],
      "Label": "ECS Instance Type",
      "Default": "ecs.xn4.small"
    },
    "KeyPair": {
      "Type": "String",
      "Description": "ECS Key Pair",
      "Label": "ECS Key Pair",
      "Default": "aliyun-ap-northeast-1"
    }
  },
  "Mappings": {},
  "Conditions": {},
  "Resources": {
    "VPC": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-1"
      },
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "VpcName": {
          "Ref": "VpcName"
        },
        "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"
              }
            }
          ]
        }
      }
    },
    "ECS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-4"
      },
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "SystemDiskCategory": "cloud_ssd",
        "IoOptimized": "optimized",
        "InternetChargeType": "PayByTraffic",
        "PrivateIpAddress": "10.0.0.2",
        "KeyPairName": {
          "Ref": "KeyPair"
        },
        "VpcId": {
          "Ref": "VPC"
        },
        "HostName": "poc",
        "ImageId": {
          "Ref": "ImageId"
        },
        "InstanceChargeType": "Postpaid",
        "VSwitchId": {
          "Ref": "VSwitch-ECS"
        },
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "InternetMaxBandwidthOut": 1,
        "InstanceName": "poc",
        "InternetMaxBandwidthIn": 200,
        "SecurityGroupId": {
          "Ref": "SG"
        },
        "Period": 1,
        "AllocatePublicIP": "true"
      }
    },
    "SG": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-5"
      },
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "VPC"
        },
        "SecurityGroupName": "poc-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"
              }
            }
          ]
        }
      }
    }
  },
  "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"
        ]
      }
    },
    "EcsZoneId": {
      "Description": "Ecs Zone id of created instance.",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "ZoneId"
        ]
      }
    },
    "InstanceId": {
      "Description": "ECS Instance Id",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "InstanceId"
        ]
      }
    },
    "PublicIp": {
      "Description": "Public IP address",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "PublicIp"
        ]
      }
    },
    "PrivateIp": {
      "Description": "ECS Private IP address",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "PrivateIp"
        ]
      }
    },
    "HostName": {
      "Description": "ECS Host Name",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "HostName"
        ]
      }
    }
  }
}

このままROSスタックを実行すれば、ecs.xn4.smallでCentOSのECSが起動します。

重要なポイント

従量課金

        "InstanceChargeType": "Postpaid",

InstanceChargeTypeを
Postpaidにしておかないと
サブスクリプションに変わり、月額になります。
注意しましょう。

ALIYUN::ECS::Instance

はまったところ

CentOSイメージ指定

サンプルテンプレートの
ecs_vpc_instance
を参考にしたのですが

    "ImageId": {
      "Type": "String",
      "Description": "ECS Image",
      "Label": "ECS Image",
      "Default": "centos_7"
    },

これだと動きません。
サンプルテンプレートも動きませんでした。 :sob:
正しくは下記のようになります。

    "ImageId": {
      "Type": "String",
      "Description": "ECS Image",
      "Label": "ECS Image",
      "Default": "centos_7_04_64_20G_alibase_201701015.vhd"
    },

まとめ

すぐにECSが最小価格単位で起動できる環境が整うと
検証とかでやりやすく、とても便利になります。

2
0
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
2
0